Android:显示不带(底部)导航栏的对话段
我找到了一种方法来防止在打开对话框时显示底部导航栏(沉浸式模式)。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论