22

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

FROM

enter image description here

TO

dark status bar

Sazid
  • 2,747
  • 1
  • 22
  • 34

2 Answers2

77

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);
IteratioN7T
  • 363
  • 8
  • 21
Sazid
  • 2,747
  • 1
  • 22
  • 34
2

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"));
            }
        }
    }
Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80
Jian Li
  • 71
  • 7