Unable To Hide Navigation Bar during AlertDialog/LoginDialog

user3585761 picture user3585761 · May 7, 2014 · Viewed 8.9k times · Source

I'm attempting to hide the navigation bar globally through my app running Android 4.2.2

I have managed to use the following (admitadly hackish) method of implementing:

getWindow().getDecorView().setSystemUiVisibility(8);

Which successfully removes the Navigation bar (the fact it is hackish is perfectly fine - this is for a kiosk so it will only be installed on a limited number of devices)

Now I'm attempting to remove the navigation bar in places other than my MainActivity - such as when it reappears during an AlertDialog/LoginDialog.

I'm attempting to use:

public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(),R.style.HoloDarkDialog));
    LayoutInflater inflater = getActivity().getLayoutInflater();

    variables = SingletonVariables.getInstance();

    view = inflater.inflate(R.layout.login, null);
    EditText userEditText = (EditText) view.findViewById(R.id.loginUserIdEditText);
    getWindow().getDecorView().setSystemUiVisibility(8);

However this result in the error:

The method getWindow() is undefined for the type LoginDialog

Does anyone know of a way this might be avoided?

Edit: (additional requested source code)

// Function to handle show dialog
public void showLogin(View view, String whichActivity) {
    pd = new ProgressDialog(this.getApplicationContext());
    pd.setMessage("Logging in, Please wait....");

    LoginDialog logindialog = new LoginDialog();
    logindialog.setWhichActivity(whichActivity);
    logindialog.show(getFragmentManager(), "MyLogin");
}

Answer

cczheng picture cczheng · Oct 11, 2018

try this code

@Override
public void show() {
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    super.show();
    int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_FULLSCREEN;
    this.getWindow().getDecorView().setSystemUiVisibility(uiOptions);
    this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

}