首页 > 解决方案 > 隐藏活动重新创建的状态栏+导航栏

问题描述

我正在更改我的应用程序的主题并为此使用重新创建。在 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) {}
    }
}

谢谢!

标签: androidandroid-statusbarandroid-navigation-bar

解决方案


推荐阅读