As you know we can set the windowLightStatusBar
from xml by following codes.
<item name="android:windowLightStatusBar">true</item>
i need to change this attribute true to false or false to true by programmatically. Is there a way to achive it?
set this if you want to change icons colors
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
and to reset to default set this
.setSystemUiVisibility(0);
but if you want to change background color of statusBar use this
getWindow.setStatusBarColor(ContextCompat.getColor(activity,R.color.my_statusbar_color));
[Update for API 26]
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS)
} else {
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
} else {
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}
}
and to clear it
window.insetsController?.setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS)
I believe this is the correct way to turn on and turn off.
if (on) {
View view = getWindow().getDecorView();
view.setSystemUiVisibility(view.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
View view = getWindow().getDecorView();
view.setSystemUiVisibility(view.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
Hidro's answer is almost correct, but WindowInsetsControllerCompat needs to be called as a function to work, otherwise it claims there is an unresolved reference in my case.
For Kotlin:
WindowInsetsControllerCompat(window, yourView).isAppearanceLightStatusBars = true
For Java:
WindowInsetsControllerCompat(getWindow(), yourView).setAppearanceLightStatusBars(true)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With