根据请求,我会尝试让Android应用程序全屏显示。我关注过Enable fullscreen mode,但在显示对话框时,导航菜单(主页按钮、后退按钮等)在显示对话框时再次显示。有没有办法禁用它?
我基于Fullscreen活动模板制作了一个示例应用程序,并观察到了相同的行为:
发布于 2021-07-27 16:05:25
默认情况下,对话框窗口是可聚焦的,并且可聚焦窗口会导致退出全屏模式。
为了解决这个问题,你可以尝试按照here中描述的那样给你的对话框设置FLAG_NOT_FOCUSABLE
标志,但是请注意,诸如ANR这样的系统对话框仍然会导致退出。
发布于 2021-07-27 21:37:18
根据link @ceribadev shared中的答案,共享我的解决方案:
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
// Here's the magic..
try {
// Set the dialog to not focusable (makes navigation ignore us adding the window)
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
// Show the dialog!
dialog.setOnShowListener(dialogInterface -> {
// Set the dialog to immersive
dialog.getWindow().getDecorView().setSystemUiVisibility(dialog.getOwnerActivity().getWindow().getDecorView().getSystemUiVisibility());
// Clear the not focusable flag from the window
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
});
} catch (Exception e) {
e.printStackTrace();
}
return dialog;
}
https://stackoverflow.com/questions/68535922
复制相似问题