2 回答
TA贡献1824条经验 获得超6个赞
按照这个答案https://stackoverflow.com/a/23207365/8531215,我已经测试过并且工作正常!onCreateDialog()
稍微修改一下方法
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
AlertDialog alertD = builder.create();
alertD.setView(view);
Dialog dialog = alertD.create();
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
//Show the dialog!
dialog.show();
//Set the dialog to immersive sticky mode
dialog.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
//Clear the not focusable flag from the window
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
return alertD;
}
TA贡献1845条经验 获得超8个赞
根据这里的文档:
实施 onWindowFocusChanged()。如果获得窗口焦点,您可能需要重新隐藏系统栏。如果您失去窗口焦点,例如由于对话框或弹出菜单显示在您的应用程序上方,您可能想要取消您之前使用 Handler.postDelayed() 或类似的东西安排的任何未决的“隐藏”操作。
所以我建议你做的是,改变你的代码MyActivity.java
:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
hideSystemUI();
}
到:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (!hasFocus){
//we lost focus due to DialogFragment
hideSystemUI();
}
}
添加回答
举报