解决全屏Activity弹出Dialog 状态栏出现的问题

问题描述:在一个Activity中设置全屏,隐藏状态栏等

//隐藏虚拟按键,并且全屏
      if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
          View v = this.getWindow().getDecorView();
          v.setSystemUiVisibility(View.GONE);
      } else if (Build.VERSION.SDK_INT >= 19) {
          //for new api versions.
          View decorView = getWindow().getDecorView();
          int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                  | View.SYSTEM_UI_FLAG_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
          decorView.setSystemUiVisibility(uiOptions);
      }

现在在这里需要做一个下载显示进度的dialog。发现显示出来dialog的时候状态栏出现了,而顶部的view 会被遮挡一部分。
于是想到是因为dialog show的时候window的属性被改变了,于是在show之前对dialog设置

        percentProgressBar?.window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)

但是这个会导致一个问题。会导致点击事件穿透Dialog 而触发到下层的Activity。所以show之后要清除掉他的flag,并且需要再设置一下状态栏的代码

//隐藏虚拟按键,并且全屏
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
}

                    percentProgressBar?.window?.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

你可能感兴趣的:(解决全屏Activity弹出Dialog 状态栏出现的问题)