如何退出沉浸模式并返回默认的 Android UI 布局?

问题描述

我正在尝试在我的一个片段中使用粘性沉浸式模式。然后当片段被销毁时,返回到默认的 UI 视图。

这是我的代码:

override fun onViewCreated(view: View,savedInstanceState: Bundle?) {
        super.onViewCreated(view,savedInstanceState)

    hideSystemUI()
}

override fun onDestroyView() {
    super.onDestroyView()
    showSystemUI()
}

private fun hideSystemUI() {
    activity?.window?.decorView?.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            // Set the content to appear under the system bars so that the
            // content doesn't resize when the system bars hide and show.
            or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            // Hide the nav bar and status bar
            or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            or View.SYSTEM_UI_FLAG_FULLSCREEN)
}

private fun showSystemUI() {
    activity?.window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
}

当我进入片段时,粘性沉浸模式有效,但当它被销毁时,状态栏和应用程序栏中会出现间隙。它看起来像这样:

enter image description here

应用栏也覆盖了屏幕上的一些文本视图。如何正确退出粘性沉浸模式并在片段销毁时将其恢复为默认行为?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)