How to set activity to fullscreen mode in Android? [duplicate]
Asked Answered
B

4

26

How to set full screen mode for activity in Android? I am using the following code to set full screen but it generates an error:

Exception:

android.util.AndroidRuntimeException: 
    requestFeature() must be called before adding content.         

Code:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,        
                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Beaty answered 12/9, 2012 at 13:0 Comment(1)
Hello all , Problem solved when I write code before setContentView(R.layout.main); . Thank you! All for your answers.Beaty
A
61

please check the code

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main);
}

and note it is set before setting the content view

Addington answered 12/9, 2012 at 13:2 Comment(4)
just change your set content view to after feature no title thats the error shownAddington
Thank you! Problem solved... Now no any exception in code. Thanks a lot.Beaty
You might still see another error specifically with Amazon devices. You need to call requestWindowFeature before super.onCreate(). See the following answer: https://mcmap.net/q/513380/-how-to-set-activity-to-fullscreen-mode-in-android-duplicateSoembawa
is there any xml equivalent for this ?Gloze
M
13

try this in AndroidManifest:

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
Milla answered 12/9, 2012 at 13:2 Comment(1)
This code I used in MAIN activity. Activity name already declared in AndroidManifest.Beaty
B
4
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
Brocatel answered 12/9, 2012 at 13:9 Comment(3)
No Mayank this code also not work for meBeaty
Code: public class Draw extends Activity { SignatureView sv; RelativeLayout rLayout1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); rLayout1 = (RelativeLayout) findViewById(R.id.relativeLayout1); // Set full screen view getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); sv = new SignatureView(this, null); rLayout1.addView(sv); sv.requestFocus(); } } This is my codeBeaty
@RanjitChandel setcontent view should come afterwards check my code belowAddington
A
2

put requestWindowFeature first in your code....like this...

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Abeabeam answered 12/9, 2012 at 13:11 Comment(1)
Hello all , Problem solved when I write code before setContentView(R.layout.main); . Thank you! All for your answers.Beaty

© 2022 - 2024 — McMap. All rights reserved.