Android:显示不带(底部)导航栏的对话段

发布于 2025-01-20 02:51:51 字数 1507 浏览 1 评论 0原文

我找到了一种方法来防止在打开对话框时显示底部导航栏(沉浸式模式)。

    private fun showDialogImmersiveFullscreen(dialog: Dialog) {
        dialog.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
        dialog.show()

        // set the dialog to immersive sticky mode
        dialog.window?.decorView?.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        )

        // clear the not focusable flag from the window
        dialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
    }

它工作正常,我在显示转换时没有看到导航栏。

当尝试使用 DialogFragment 实现它时,问题就开始了。当我使用下面的函数打开 DialogFragment 时,我看到导航栏出现了一小会儿,然后立即消失了。这个想法根本不是要表现出来......

    private fun showDialogImmersiveFullscreen(dialogFragment: DialogFragment?, transaction: FragmentTransaction, tag: String) {
        dialogFragment?.dialog?.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
        dialogFragment?.show(transaction, tag)
        supportFragmentManager.executePendingTransactions()

        dialogFragment?.dialog?.window?.decorView?.setSystemUiVisibility(
            window.decorView.getSystemUiVisibility()
        )

        // clear the not focusable flag from the window
        dialogFragment?.dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
    }

我做错了什么?

I've found a way to prevent showing bottom navigation bar (immersive mode) at the moment of opening a Dialog.

    private fun showDialogImmersiveFullscreen(dialog: Dialog) {
        dialog.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
        dialog.show()

        // set the dialog to immersive sticky mode
        dialog.window?.decorView?.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        )

        // clear the not focusable flag from the window
        dialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
    }

It works fine and I don't see the navigation bar at the display transition.

The problems start while trying to achieve it with DialogFragment. At the time I open DialogFragment using the function below, I see the navigation bar appearing for a v. short moment and then it immediately disappears. The idea is not to show it at all...

    private fun showDialogImmersiveFullscreen(dialogFragment: DialogFragment?, transaction: FragmentTransaction, tag: String) {
        dialogFragment?.dialog?.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
        dialogFragment?.show(transaction, tag)
        supportFragmentManager.executePendingTransactions()

        dialogFragment?.dialog?.window?.decorView?.setSystemUiVisibility(
            window.decorView.getSystemUiVisibility()
        )

        // clear the not focusable flag from the window
        dialogFragment?.dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
    }

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文