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

fsilvestre
  • 299
  • 2
  • 10
  • 1
    possible duplicate of [FullScreen Activity in android?](http://stackoverflow.com/questions/2868047/fullscreen-activity-in-android) – Marek Sebera Jan 26 '12 at 18:09
  • well see Marek Sebera comment and the link in it...the answer is given for both ways(programmatic and non-programmatic) – Navin Ilavarasan Jan 26 '12 at 18:22
  • 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. – Maxim Jan 26 '12 at 18:25
  • do you read my question? the link show how make this in onCreate method, i want know outside onCreate. – fsilvestre Jan 26 '12 at 18:27
  • Maxim, my project need set fullscreen outside onCreate.i understand that onCreate is the right place, but is possible set outside? – fsilvestre Jan 26 '12 at 18:30
  • 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. – Maxim Jan 30 '12 at 16:23
  • @Maxim Thanks !! This is my first question in StackOverFlow, next time i will do this – fsilvestre Jan 31 '12 at 17:25

5 Answers5

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

fsilvestre
  • 299
  • 2
  • 10
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.

kabuko
  • 36,028
  • 10
  • 80
  • 93
  • 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. – Martin Foot Jan 26 '12 at 18:38
  • 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 content – fsilvestre Jan 26 '12 at 18:49
  • 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. – kabuko Jan 26 '12 at 18:52
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 ? ...

Amsheer
  • 7,046
  • 8
  • 47
  • 81
0

Try this:

View decorView = getWindow().getDecorView();

int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Cody
  • 4,353
  • 4
  • 39
  • 42
-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);

...
}
Adam Lear
  • 38,111
  • 12
  • 81
  • 101