Set Full Screen out onCreate

浪尽此生 提交于 2019-12-04 03:08:59

问题


I can only set my Activity to Full Screen in onCreate method (before setContentView)?

Is there any way I can set to full screen outside of onCreate?

Thanks


回答1:


Is possible! Adding this code.


    // go full screen
    WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes();
    attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    mActivity.getWindow().setAttributes(attrs);

    // go non-full screen
    WindowManager.LayoutParams attrs = mActivity.getWindow().getAttributes();
    attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
    mActivity.getWindow().setAttributes(attrs);




回答2:


The docs for Window.requestFeature says:

This must be called before setContentView().

so no, I don't believe there is another way to set to full screen after you call setContentView.




回答3:


getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);   

Use this before setting layout .Because you are trying to set your layout into fullscreen. Why you need outside of on create method ? ...




回答4:


Try this:

View decorView = getWindow().getDecorView();

int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);



回答5:


@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

     **requestWindowFeature(Window.FEATURE_NO_TITLE);
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);**

     setContentView(R.layout.activity);

...
}


来源:https://stackoverflow.com/questions/9023023/set-full-screen-out-oncreate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!