【问题标题】:Android API level 30 setSystemBarsAppearance doesn't overwrite theme dataAndroid API 级别 30 setSystemBarsAppearance 不会覆盖主题数据
【发布时间】:2021-02-05 10:43:17
【问题描述】:

我拥有 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)
}

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

我的问题是,这是打算这样还是我在某个地方遗漏了什么?

【问题讨论】:

  • 疯狂的机器人。也不起作用,我只是使用已弃用的 API,一切正常(别无选择)¯_(ツ)_/¯

标签: android android-theme android-styles android-11 windowinsets


【解决方案1】:

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

【讨论】:

  • 对我不起作用,标志未清除到黑暗状态栏
【解决方案2】:

如果您在主题中将 android:windowLightStatusBar 设置为 true,则需要执行已弃用的调用(删除系统 UI 标志)才能使其正常工作。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    • 2020-07-11
    • 2020-03-27
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 2022-11-24
    相关资源
    最近更新 更多