17

How do I create a full screen mode in XML irregardless of how small what contents are in it?

Here's my "show.xml" code:

<LinearLayout android:orientation="vertical"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_gravity="center">    

<Button android:id="@+id/ok_btn" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:typeface="sans" android:text="ok"></Button>

</LinearLayout>

I want to display it like another full screen page, with black background, like a main.xml. In this case, its like a pop-up screen. Removing or changing the android:layout_width and android:layout_heigh don't work. help please! :(

Sushi
  • 225
  • 1
  • 3
  • 6
  • I dont understand how do you mean that it looks like pop-up screen. Maybe you are creating it as a dialog instead of activity? You should call it like this: Intent myIntent = new Intent(view.getContext(),MyActivity.class); startActivityForResult(myIntent, 0); – Martin Nuc Oct 21 '11 at 00:43
  • Does this answer your question? [Fullscreen Activity in Android?](https://stackoverflow.com/questions/2868047/fullscreen-activity-in-android) – Vega Sep 24 '20 at 23:03

4 Answers4

41

Afaik you can't do fullscreen in xml. You have two choices:

  1. AndroidManifest.xml in activity's section
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
  1. in onCreate() before calling setContentView
requestWindowFeature( Window.FEATURE_NO_TITLE );

getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN,
                      WindowManager.LayoutParams.FLAG_FULLSCREEN );
lue
  • 449
  • 5
  • 16
Martin Nuc
  • 5,604
  • 2
  • 42
  • 48
20

As the other answer doesn't work for me:


<style name="AppTheme.Fullscreen">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

Add this style to your styles.xml


<activity
    android:name=".TitlesActivity"
    android:theme="@style/AppTheme.Fullscreen">

Make sure your activity in the AndroidManifest.xml refers to your theme.

Felix
  • 824
  • 8
  • 21
0

Add in AndroidManifest.xml:

 <activity
            android:name=".MainActivity"
            android:theme="@style/Theme.ControllerApp.NoActionBar"/>

Add in MainActivity.java:

 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

This worked for me.

Shiv Buyya
  • 3,770
  • 2
  • 30
  • 25
0

For some reason, previous answers did not work for me, but this line from GeeksForGeeks works like a miracle:

Made these changes in your manifest.xml file

android:theme="@style/Theme.AppCompat.Light.NoActionBar"
broland
  • 11
  • 2