Search code examples
javaandroidandroid-studiofullscreen

<Android> Full screen mode is broken and a transparent navigation bar appears when alert is made


I'm developing application for android tablet and wants it to be always keeping full screen mode. I set flags for that, but when the alert dialog appears it breaks. When it first appears it keeps full screen, however, when alert dialog is made again, the full screen mode is broken and a transparent navigation bar appears. Why does the full screen mode fluctuate? Below is my code.

AlertDialog.Builder warning = new AlertDialog.Builder(my_context);
                        View view = ActivityTeetimeDetail.this.getLayoutInflater().inflate(my_alert_layout,null);
                        warning.setView(view);
                        AlertDialog dialog = warning.create();
                        TextView alertTitle = (TextView) view.findViewById(R.id.setAlertTitle);
                        alertTitle.setText("Text");
                        TextView alertContent = (TextView) view.findViewById(R.id.setAlertContent);
                        alertContent.setText("Text");
                        Button confirm = (Button) view.findViewById(R.id.dialog_button_confirm);
                        confirm.setText(R.string.Alert_Confirm);
                        confirm.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                dialog.dismiss();
                            }
                        });
                        Button cancel = (Button) view.findViewById(R.id.dialog_button_cancel);
                        cancel.setVisibility(View.INVISIBLE);
                        dialog.setCancelable(true);
                        dialog.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                                View.SYSTEM_UI_FLAG_FULLSCREEN |
                                View.SYSTEM_UI_FLAG_LAYOUT_STABLE|
                                View.SYSTEM_UI_FLAG_IMMERSIVE|
                                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION|
                                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|
                                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

                        dialog.show();

Solution

  • you are almost there, you just need to clear the focus from alertdialog that is navigationbar stays hidden.

    AlertDialog.Builder warning = new AlertDialog.Builder(my_context);
                        View view = ActivityTeetimeDetail.this.getLayoutInflater().inflate(my_alert_layout,null);
                        warning.setView(view);
                        AlertDialog dialog = warning.create();
                        TextView alertTitle = (TextView) view.findViewById(R.id.setAlertTitle);
                        alertTitle.setText("Text");
                        TextView alertContent = (TextView) view.findViewById(R.id.setAlertContent);
                        alertContent.setText("Text");
                        Button confirm = (Button) view.findViewById(R.id.dialog_button_confirm);
                        confirm.setText(R.string.Alert_Confirm);
                        confirm.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                dialog.dismiss();
                            }
                        });
                        Button cancel = (Button) view.findViewById(R.id.dialog_button_cancel);
                        cancel.setVisibility(View.INVISIBLE);
                        dialog.setCancelable(true);
    
                   // add this to your code.
                   dialog.getWindow().
                   setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                   WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    
                        dialog.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                                View.SYSTEM_UI_FLAG_FULLSCREEN |
                                View.SYSTEM_UI_FLAG_LAYOUT_STABLE|
                                View.SYSTEM_UI_FLAG_IMMERSIVE|
                                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION|
                                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|
                                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    
                        dialog.show();