全屏模式损坏,弹出警报时出现透明导航栏。

huangapple go评论68阅读模式
英文:

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

问题

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

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();
英文:

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(&quot;Text&quot;);
                        TextView alertContent = (TextView) view.findViewById(R.id.setAlertContent);
                        alertContent.setText(&quot;Text&quot;);
                        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();

答案1

得分: 0

你已经接近成功了,你只需要清除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("文本");
TextView alertContent = (TextView) view.findViewById(R.id.setAlertContent);
alertContent.setText("文本");
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().
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();
英文:

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(&quot;Text&quot;);
TextView alertContent = (TextView) view.findViewById(R.id.setAlertContent);
alertContent.setText(&quot;Text&quot;);
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();

huangapple
  • 本文由 发表于 2020年10月13日 08:55:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/64327010.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定