以下代码段隐藏了导航栏和状态栏:
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)
}
}