17

Pre-Android 11(API 级别 30)我已经 <item name="android:windowLightStatusBar">true</item> 在我的主题中设置,并且在代码中另外更改了这个(需要时)

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() }
}

然而,Android-30 增加了一种新的控制方式

fun setLightStatusBar(){ 
    window?.insetsController?.setSystemBarsAppearance(APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS)
} 

fun setDarkStatusBar(){
    window?.insetsController?.setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS)
}

但我的问题是这不能覆盖主题集值,因此我需要全部使用样式或全部使用代码。

我的问题是,如果这是打算这样,还是我在某处遗漏了什么?

4

2 回答 2

3

我从中删除<item name="android:windowLightStatusBar">true/false</item>styles.xml它工作正常。

于 2020-12-05T17:44:02.900 回答
2

如果您在主题中设置android:windowLightStatusBartrue,则需要执行已弃用的调用,该调用会删除系统 UI 标志,以使其正常工作。

activity.window.decorView.run {
    systemUiVisibility =
        systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv()
}

似乎两者WindowInsetsControllersystemUiVisibility控制状态栏主题,但机制不同。

于 2021-08-26T08:37:06.773 回答