android:如何在全屏对话框中隐藏底部按钮

问题描述 投票:0回答:1

我试图全屏显示对话框时隐藏导航按钮。我已经按照以下示例操作:Android fullscreen dialog

但是,只要我触摸一个按钮,它们就会再次出现。

有没有办法正确隐藏它们?

nav buttons to hide

感谢

android modal-dialog android-alertdialog
1个回答
0
投票

以下代码段隐藏了导航栏和状态栏:

window.decorView.apply {
    // Hide both the navigation bar and the status bar.
    // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
    // a general rule, you should design your app to hide the status bar whenever you
    // hide the navigation bar.
    systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN
}

来自https://developer.android.com/training/system-ui/navigation

尽管如此,您需要做两件事。

  • 首先,将windowFullScreen设置为true以允许对话框绘制屏幕中的每个像素。 (即使用任何全屏主题)。

  • 然后,在对话框上,将systemUiVisibility设置为View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

这将停止显示导航栏,直到您重置标志或关闭对话框。

完整的代码段:

class SomeActivity {

    fun showDialog() {
        FullScrenDialog()
            .apply {
                setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_NoTitleBar_Fullscreen)
            }
            .show(supportFragmentManager, "TAG")
    }

}


class FullScrenDialog : DialogFragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        dialog.window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        return inflater.inflate(R.layout.dialog, container)
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.