Home » Android » android – Set Full Screen out onCreate

android – Set Full Screen out onCreate

Posted by: admin June 15, 2020 Leave a comment

Questions:

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

How to&Answers:

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);

Answer:

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.

Answer:

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 ? …

Answer:

Try this:

View decorView = getWindow().getDecorView();

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

Answer:

@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);

...
}