AlertDialog 显示 SystemUiVisibility

AlertDialog shows SystemUiVisibility

我正在制作一个 android 游戏,我使用 setSystemUiVisibility 设置我的 SystemUiVisibility 以不显示顶部栏和其他系统 ui,但是现在当你在游戏中死亡时我想显示带有分数的 AlertDialog。当我显示 AlertDialog 时,它会带回 SystemUiVisibility,我不想让这种情况发生。有人知道如何解决这个问题。这是我现在用于 AlertDialog 的代码:

dlgAlert.setMessage("You lost, you hit the right color " + Points + " times");
                dlgAlert.setTitle("You died");
                dlgAlert.setPositiveButton("OK", null);
                dlgAlert.create().show();

在创建对话框时使其不可聚焦(这样我们就不会触发用户交互),然后在显示后使其可聚焦。

    dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

//Show the dialog!
dialog.show();

//Set the dialog to immersive
dialog.getWindow().getDecorView().setSystemUiVisibility(
context.getWindow().getDecorView().getSystemUiVisibility());

//Clear the not focusable flag from the window
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);