James Newton James Newton - 1 month ago 14
Android Question

Android: making an app fullscreen

What is the simplest change that I can make to a new Blank Activity, as created by the latest version of Android Studio, to get the app to appear fullscreen?

I want to create a fullscreen Android application. I'm working with Android Studio.
This post suggests that I add a line such as ...

android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"


... to the AndroidManifest.xml file, as shown below:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lexogram.james.blackslate" >

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.lexogram.james.blackslate.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


When I do this, the app compiles but it crashes on launch. If I remove the line, the app runs fine, but with the action bar and a title bar, as also noted by other users.

This is my first attempt at creating an Android app, so my app is hardly altered from the original Hello World example.

EDIT:
I created a new project, and made just this one change to it. Here is an extract from the error log:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lexogram.james.test/com.lexogram.james.test.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)...


NOTE: I am testing on a old Samsung SGH-T499Y, running Android 2.2 (Froyo)

Answer

You are getting this problem because the activity you are trying to apply the android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"> to is extending ActionBarActivity which requires the AppCompat theme to be applied.

Extend your activity from Activity rather than from ActionBarActivity

You might have to change your Java class accordingly little bit.

If you want to remove status bar too then use this before setContentView(layout) in onCreateView method

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