gpt4 book ai didi

android - 状态栏字体颜色不同步变化

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:10:17 25 4
gpt4 key购买 nike

我正在更改我的 windowdecorView 以基本上在 View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 之间切换,这取决于我的滚动位置看法。

因为我同时更改了 ActionBar 和状态栏,所以我希望这两个更改至少是即时的。但是我注意到在执行 window.decorView.systemUiVisibility = newIntWithToggledLightMode 和呈现新状态栏模式之间有 50 毫秒的延迟。我不想将我的工具栏更改放置在 postDelay 处理程序中,只是为了协调它们与状态栏更改的同时外观。我以为我可以覆盖 onSystemUiVisibilityChangeInterface 以在状态栏 ui 更新时收到通知,但这似乎只有在我使状态栏不可见时才会触发,而不仅仅是更改外观模式。有没有人遇到过这个问题并想出了一个更优雅的解决方案?

最佳答案

我只是调查了试图复制您的问题,但我没有遇到您所说的延迟...在我的示例中,我通过单击按钮模拟了不断变化的背景事件。希望对您有所帮助,我在这里分享我的代码:

Activity 的属性

private val isLight get () = (window.decorView.systemUiVisibility and SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) > 0

activity 的 onCreate 中的按钮初始化

button.setOnClickListener {
if (isLight) {
setStatusBarColors(
decorView.systemUiVisibility and SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv(),
ContextCompat.getColor(decorView.context, android.R.color.holo_green_dark)
)
} else {
setStatusBarColors(
decorView.systemUiVisibility or SYSTEM_UI_FLAG_LIGHT_STATUS_BAR,
ContextCompat.getColor(decorView.context, android.R.color.holo_red_light)
)
}
}

setStatusBarColors() 函数

private fun setStatusBarColors(flags: Int, @ColorInt bgColor: Int) {
window.decorView.systemUiVisibility = flags
window.statusBarColor = bgColor
toolbar.setBackgroundColor(bgColor)
}

这段代码导致如下结果(如果没有运行请点击下面的GIF): enter image description here

关于android - 状态栏字体颜色不同步变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55820241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com