How to change the status bar notification icons' color/tint in android (marshmallow and above 23+)?

前端 未结 2 1320
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 13:40

As the title says, how do I change the status bar icons\' color to have a dark tint instead of the default white.

FROM

TO

相关标签:
2条回答
  • 2020-12-02 14:09

    Below is sample code, change status bar color when switch between portrait&landscapse. portrait mode : light bar, dark icon; landscape mode : dark bar, light icon; Theme: "Theme.AppCompat.Light"

        @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
            Window window = getWindow();
            View decorView = window.getDecorView();
            if(Configuration.ORIENTATION_LANDSCAPE == newConfig.orientation) {
                decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    window.setStatusBarColor(Color.parseColor("#55000000")); // set dark color, the icon will auto change light
                }
            } else {
                decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    window.setStatusBarColor(Color.parseColor("#fffafafa"));
                }
            }
        }
    
    0 讨论(0)
  • 2020-12-02 14:30

    For the status bar icons' to have a dark tint instead of the default white, add the following tag in your styles.xml (or more precisely in values-v23/styles.xml) file:

    <item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
    

    You can also change the flag at runtime by setting it to any View:

    View yourView = findViewById(R.id.your_view);
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (yourView != null) {
            yourView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }
    

    If you want to reset the changes, clear the flag like this:

    yourView.setSystemUiVisibility(0);
    
    0 讨论(0)
提交回复
热议问题