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! :(

2
  • 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, 2011 at 0:43
  • Does this answer your question? Fullscreen Activity in Android?
    – Vega
    Sep 24, 2020 at 23:03

4 Answers 4

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 );
1
  • 1
    This works for me. For 2nd option (when code in onCreate) add the given two lines before setContentView method call. Apr 30, 2014 at 10:54
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.

2
  • 1
    This is just more proper IMO
    – RyPope
    Oct 19, 2016 at 23:39
  • 1
    Agreed, the question was about fullscreen in XML. This should be the accepted answer.
    – Grisgram
    Jan 6, 2018 at 7:41
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.

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.