<Android>全屏模式被打破,当提醒时出现透明导航栏

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

我正在为 android 平板电脑开发应用程序,并希望它始终保持全屏模式。 我为此设置了标志,但是当出现警报对话框时它中断了。 当它第一次出现时它保持全屏,但是,当再次出现警告对话框时,全屏模式被打破并出现一个透明的导航栏。 为什么全屏模式会波动?下面是我的代码。

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();

你就快完成了,你只需要清除 alertdialog 的焦点,导航栏保持隐藏状态。

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();