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);
Jonik
  • 80,077
  • 70
  • 264
  • 372
Ranjitsingh Chandel
  • 1,479
  • 6
  • 19
  • 33

4 Answers4

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

Athul Harikumar
  • 2,501
  • 18
  • 16
13

try this in AndroidManifest:

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
imperator_sp
  • 1,216
  • 10
  • 16
4
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
Roadies
  • 3,309
  • 2
  • 30
  • 46
  • No Mayank this code also not work for me – Ranjitsingh Chandel Sep 12 '12 at 13:16
  • **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 code – Ranjitsingh Chandel Sep 12 '12 at 13:17
  • @RanjitChandel setcontent view should come afterwards check my code below – Athul Harikumar Sep 12 '12 at 13:19
2

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

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Priyank Patel
  • 12,244
  • 8
  • 65
  • 85