1

Per request, I'm trying to make an Android application fullscreen. I've followed Enable fullscreen mode, but when showing a dialog, the navigation menu (home button, back button, etc...) displays again while the dialog is shown. Is there a way to disable this?

I made a sample app, based on the Fullscreen Activity template, and I observe the same behavior: Fullscreen Activity Fullscreen Dialog

lgdroid57
  • 699
  • 14
  • 29

2 Answers2

3

Dialog window is focusable by default and focusable windows leads to the exit from fullscreen mode.

For workaround you can try to set FLAG_NOT_FOCUSABLE flag to your dialogs as described here but note that system dialogs such as ANR will still lead to an exit.

protohope
  • 46
  • 2
  • Thanks for sharing! I adapted the solution slightly for a base dialog class. It's too long to post in a comment, so I'll post it as another answer, but I'll mark your answer as accepted. :) – lgdroid57 Jul 27 '21 at 13:35
1

Sharing my solution, based on the answer in the 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;
}
lgdroid57
  • 699
  • 14
  • 29