Q:

How do you keep the Navigation Bar hidden when opening dialogs?

I have a theme that has a Theme.AppCompat.Dialog parent. The thing is all my activities keeps the navigation bar hidden, but when a dialog is opened, it returns with a sometimes black and sometimes transparent background color. Is there a way to keep it hidden during opening dialogs?

A:

I finally solved this by overriding the show() method of the custom dialog that I have.
@Override
public void show() {
    // Set the dialog to not focusable.
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

    // Show the dialog with NavBar hidden.
    super.show();

    // Set the dialog to focusable again.
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
}

A:

I used @John Ernest Guadalupe's idea to solve my same problem with an AlertDialog but with his solution the navigation bar popped up for a quarter second and after gone (nasty flick). I didn't like this so i used a little trick for eliminate it:

Hide the navigation bar before showing the dialog.

// Flags for full-screen mode:
static int ui_flags =
        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_FULLSCREEN |
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;

// Set up the alertDialogBuilder:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this)
    .setCancelable(false)
    .setIcon(R.drawable.outline_info_black_48)
    .setTitle("Bla")
    .setMessage("Blaa blabla.")
    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

// Create the alertDialog:
AlertDialog alertDialog = alertDialogBuilder.create();

// Set alertDialog "not focusable" so nav bar still hiding:
alertDialog.getWindow().
    setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
             WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

// Set full-sreen mode (immersive sticky):
alertDialog.getWindow().getDecorView().setSystemUiVisibility(ui_flags);

// Show the alertDialog:
alertDialog.show();

// Set dialog focusable so we can avoid touching outside:
alertDialog.getWindow().
    clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

