我将我的应用设置为全屏显示,但是当我创建并显示片段对话框时,它将退出全屏显示
我尝试两种方法,但对我没有用,请检查代码1和代码2
代码1:
加
adding <item name="android:windowFullscreen">true</item>
到我的style.xml
代码2:
在片段对话框中覆盖onShow
@Override
public void show(FragmentManager manager, String tag)
{
getDialog().getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
super.show(manager, tag);
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
getDialog().getWindow().getDecorView().setSystemUiVisibility(uiOptions);
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
}
什么都没发生,我的应用再次从全屏退出
答案 0 :(得分:1)
好的,我有自己的答案 这段代码使问题得以解决:
getDialog().getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
getDialog().getWindow().getDecorView().setSystemUiVisibility(getActivity().getWindow().getDecorView().getSystemUiVisibility());
getDialog().setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
//Clear the not focusable flag from the window
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
//Update the WindowManager with the new attributes (no nicer way I know of to do this)..
WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
wm.updateViewLayout(getDialog().getWindow().getDecorView(), getDialog().getWindow().getAttributes());
}
});
答案 1 :(得分:0)
尝试
@Override
public void show(FragmentManager manager, String tag)
{
getDialog().getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
super.show(manager, tag);
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
getDialog().getWindow().getDecorView().setSystemUiVisibility(uiOptions);
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
// add these two line
getDialog().requestWindowFeature(1);
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
答案 2 :(得分:0)
尝试一下:
@Override
public void onResume() {
// Get existing layout params for the window
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
// Assign window properties to fill the parent
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
// Call super onResume after sizing
super.onResume()
}