Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 791
Ranjit Chandel Avatar asked Sep 12 '12 13:09

Ranjit Chandel


People also ask

How do I make android activity full screen?

Using Android Studio (current version is 2.2. 2 at moment) is very easy to add a fullscreen activity. See the steps: Right click on your java main package > Select “New” > Select “Activity” > Then, click on “Fullscreen Activity”.

How do I get out of fullscreen mode on android?

Exit full screen Tap the video. At the bottom of the player, tap full screen exit .

How do I make Android Studio full screen?

This example demonstrate about How to get full screen activity in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.


4 Answers

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

like image 108
Athul Harikumar Avatar answered Sep 28 '22 16:09

Athul Harikumar


try this in AndroidManifest:

<activity android:name=".ActivityName"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
like image 44
imperator_sp Avatar answered Sep 29 '22 16:09

imperator_sp


requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
like image 27
Roadies Avatar answered Sep 28 '22 16:09

Roadies


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

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
like image 27
Priyank Patel Avatar answered Sep 25 '22 16:09

Priyank Patel