问题描述
我正在为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();