Set Full Screen out onCreate
Asked Answered
D

5

8

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

Dispirit answered 26/1, 2012 at 18:8 Comment(7)
possible duplicate of FullScreen Activity in android?Inset
well see Marek Sebera comment and the link in it...the answer is given for both ways(programmatic and non-programmatic)Lustig
Why do you want to set in somewhere else? What's wrong with onCreate? onCreate is a right place to set up Activity's options.Germanous
do you read my question? the link show how make this in onCreate method, i want know outside onCreate.Dispirit
Maxim, my project need set fullscreen outside onCreate.i understand that onCreate is the right place, but is possible set outside?Dispirit
Okay, just next time in explanation add that you do something specific and need to do it afterwards. As more details, what you do and what is going on, as better to understand what you exactly need. However, your answer is a standard way to set full screen through code. Also if you want me or somebody else read you response on comment add user name like @UserName I will get a notification then. Glad you solved your issue, good job.Germanous
@Germanous Thanks !! This is my first question in StackOverFlow, next time i will do thisDispirit
D
12

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

Dispirit answered 27/1, 2012 at 12:39 Comment(0)
M
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.

Midlothian answered 26/1, 2012 at 18:32 Comment(3)
You can call setContentView a second time outside of onCreate if you like, so as long as you call it after requesting the full screen feature it's fine. Note that it will invalidate any references to Views you have, so you will need to call findViewByID again after for each View reference.Mundane
Martin, i try use requestFeature() to set fullscreen in another method and code below a call setContentView again, but occurred a Exception: requestFeature() must be called before adding contentDispirit
You can try not calling setContentView yet in onCreate and only calling it after where you want to call requestFeature, but once you call setContentView the above applies.Midlothian
B
0
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 ? ...

Beberg answered 17/5, 2013 at 12:1 Comment(0)
L
0

Try this:

View decorView = getWindow().getDecorView();

int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Llamas answered 26/6, 2017 at 13:26 Comment(0)
C
-1
@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);

...
}
Chloris answered 5/4, 2013 at 21:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.