【问题标题】:<Android> Full screen mode is broken and a transparent navigation bar appears when alert is made<Android> 全屏模式坏了,提示时出现透明导航栏
【发布时间】:2020-10-13 12:23:07
【问题描述】:

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

【问题讨论】:

    标签: java android android-studio fullscreen


    【解决方案1】:

    你快到了,你只需要从 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();
    

    【讨论】:

    • 绝对有效!谢谢!我可以再问一个问题吗?当我应用此代码时,它总是隐藏导航栏但 setCancelable(true) 不起作用。我该如何解决这个问题?
    • 是的,它不起作用,因为我们使对话框无法聚焦。
    • 我在背景中做了一个 0% 不透明度和不可见的布局,并在弹出警报时将其设置为可见。我为该布局设置了 setOnClickListener 以便不单击背景项目并且可以关闭带有触摸背景的警报对话框。感谢您的帮助!
    • 这很好
    猜你喜欢
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-20
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    相关资源
    最近更新 更多