Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android API level 30 setSystemBarsAppearance doesn't overwrite theme data

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?

like image 664
Viktor Stojanov Avatar asked Oct 22 '20 12:10

Viktor Stojanov


2 Answers

I removed <item name="android:windowLightStatusBar">true/false</item> from styles.xml and it worked correctly.

like image 188
Ярослав Нестеров Avatar answered Nov 19 '22 14:11

Ярослав Нестеров


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.

like image 2
Hsingchien Cheng Avatar answered Nov 19 '22 12:11

Hsingchien Cheng