android - 隐藏活动重新创建的状态栏+导航栏
问题描述
我正在更改我的应用程序的主题并为此使用重新创建。在 onCreate 中,我在超级调用之前设置了我的主题。
一切与主题相关的作品都很好。但是状态栏和导航栏突然出现又消失了片刻。有没有办法解决它,所以它根本不会出现?
这是我隐藏所有代码:
fun hideWindowUI(window: Window?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window?.setDecorFitsSystemWindows(false)
val controller = window?.insetsController
controller?.hide(WindowInsets.Type.ime())
controller?.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
controller?.hide(WindowInsets.Type.systemBars())
}
else {
@Suppress("DEPRECATION")
window?.decorView?.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN)
}
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) {
try {
Utils.hideWindowUI(window)
} catch (e: NullPointerException) {}
}
}
谢谢!
解决方案
推荐阅读
- ruby - 嵌套的“if”语句不评估操作的结果
- python - 使用 crontab 执行程序
- merge - 在 SAS 中合并宏表
- sql - recordset.save 正在保存一个空文件 vbscript uft
- javascript - 如何删除同一类的所有li元素,除了jquery或javascript中的第一个li元素
- php - php exec 不会执行控制台中有关音频和视频的可执行文件
- python - 使用 http 身份验证使用 selenium/python/shell 脚本截取屏幕截图
- vba - 如何使用 VBA 和 Chromedriver 优化等待方法
- log4j2 - 运行 install4j 创建的可执行文件时的 Log4j 文件位置
- r - R 函数以按年份识别第一个正面观察