当对话框全屏显示时,我试图隐藏导航按钮。 我已经按照以下示例操作:Android fullscreen dialog
但是,只要我触摸一个按钮,它们就会再次出现。
有什么办法可以正确隐藏它们?
谢谢
以下代码段隐藏了导航栏和状态栏:
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)
}
}
,
请尝试下面的对话框代码:
final Dialog dialog = new Dialog(this);
dialog.setCancelable(false);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setGravity(Gravity.CENTER);
dialog.setContentView(R.layout.dialog_logout);
Window window = dialog.getWindow();
window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
window.getDecorView().setSystemUiVisibility(uiOptions);
dialog.show();
输出为:
我希望它对您有用。