@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;
}
2条答案
按热度按时间irtuqstp1#
对话框窗口在默认情况下是可聚焦的,可聚焦的窗口导致从全屏模式退出。
对于解决方法,您可以尝试设置
FLAG_NOT_FOCUSABLE
按此处所述标记对话框,但请注意,系统对话框(如anr)仍将导致退出。iezvtpos2#
根据中的答案共享我的解决方案link@ceribadev共享: