Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Full Screen out onCreate

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

like image 354
fsilvestre Avatar asked Jan 26 '12 18:01

fsilvestre


People also ask

Why do we need to call setContentView () in onCreate ()?

As onCreate() of an Activity is called only once, this is the point where most initialization should go: calling setContentView(int) to inflate the activity's UI, using findViewById to programmatically interact with widgets in the UI, calling managedQuery(android.

Is onCreate only called once?

OnCreate is only called once.

Why is onCreate protected?

onCreate is not private because you do want to subclass an Activity and then use the super Activity onCreate method for the subclass. Actually every Activity you design extends android. app. Activity, so if onCreate was private in that super class, then you wouldn't be able to call onCreate at all.


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

like image 181
fsilvestre Avatar answered Sep 18 '22 21:09

fsilvestre


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.

like image 20
kabuko Avatar answered Sep 20 '22 21:09

kabuko