2 回答

TA貢獻1824條經驗 獲得超6個贊
按照這個答案https://stackoverflow.com/a/23207365/8531215,我已經測試過并且工作正常!onCreateDialog()
稍微修改一下方法
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
AlertDialog alertD = builder.create();
alertD.setView(view);
Dialog dialog = alertD.create();
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
//Show the dialog!
dialog.show();
//Set the dialog to immersive sticky mode
dialog.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
//Clear the not focusable flag from the window
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
return alertD;
}

TA貢獻1845條經驗 獲得超8個贊
根據這里的文檔:
實施 onWindowFocusChanged()。如果獲得窗口焦點,您可能需要重新隱藏系統欄。如果您失去窗口焦點,例如由于對話框或彈出菜單顯示在您的應用程序上方,您可能想要取消您之前使用 Handler.postDelayed() 或類似的東西安排的任何未決的“隱藏”操作。
所以我建議你做的是,改變你的代碼MyActivity.java
:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
hideSystemUI();
}
到:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (!hasFocus){
//we lost focus due to DialogFragment
hideSystemUI();
}
}
添加回答
舉報