第一个Dialog复写onWindowFocusChanged方法,当dialog在最前面试焦点是focus否则是true,当为true时,对dialog进行全屏显示(沉浸式)控制

 @Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Log.e("TAG", "onWindowFocusChanged: hasFocus"+hasFocus);
if (hasFocus) {
fullScreenImmersive(getWindow().getDecorView());
}
}

MyAlertDialog extends Dialog

  private void fullScreenImmersive(View view) {
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_FULLSCREEN);
}

扩展
MyAlertDialog extends Dialog

 @Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
Log.e("TAG", "onAttachedToWindow: ");
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
fullScreenImmersive(getWindow().getDecorView());
}
}

@Override
public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
super.onWindowAttributesChanged(params);
Log.e("TAG", "onWindowAttributesChanged: ");
}