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
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
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);
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"));
}
}
}