微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

<Android>全屏模式已损坏,发出警报时会出现一个透明的导航栏

如何解决<Android>全屏模式已损坏,发出警报时会出现一个透明的导航栏

我正在为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();

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。