在 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)
}
但我的问题是,这不能覆盖主题设置的值,因此我需要使用样式或代码来完成全部工作。
我的问题是,这是否有意为之,还是我在某个地方漏掉了什么?