如何解决在全屏活动上显示对话框时,Android 应用程序退出全屏
根据请求,我正在尝试使 Android 应用程序全屏显示。我已经关注了 Enable fullscreen mode,但是在显示对话框时,导航菜单(主页按钮、后退按钮等)会在显示对话框时再次显示。有没有办法禁用它?
我基于全屏活动模板制作了一个示例应用,我观察到了相同的行为:
解决方法
对话框窗口默认是可聚焦的,可聚焦的窗口会导致退出全屏模式。
作为解决方法,您可以尝试按照 here 所述为您的对话框设置 FLAG_NOT_FOCUSABLE
标志,但请注意,ANR 等系统对话框仍会导致退出。
根据 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;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。