Pre-Android 11 (API Level 30) I had
<item name="android:windowLightStatusBar">true</item>
set in my theme and was additionally changing this (when needed) in the the code with
fun setLightStatusBar(){
window?.decorView?.let { it.systemUiVisibility = it.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR }
}
fun setDarkStatusBar(){
window?.decorView?.let { it.systemUiVisibility = it.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() }
}
However, Android-30 adds a new way to control with
fun setLightStatusBar(){
window?.insetsController?.setSystemBarsAppearance(APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS)
}
fun setDarkStatusBar(){
window?.insetsController?.setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS)
}
but my issue is that this cannot overwrite the theme-set values and thus I need to either do it all with styles or all in code.
My question is if this is intended to be like this or am I missing something somewhere?
I removed <item name="android:windowLightStatusBar">true/false</item>
from styles.xml
and it worked correctly.
If you set android:windowLightStatusBar
to true
in your theme, you need to do the deprecated call, which removes the system UI flag, to make it work.
activity.window.decorView.run {
systemUiVisibility =
systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
}
It seems like both WindowInsetsController
and systemUiVisibility
both controls the status bar theme, but in different mechanisms.
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