Search code examples
androidxmlappcompatactivity

Android set view flags for AppCompat activity with XML


I have the following activity in my AndroidManifest.xml file:

<activity
        android:name=".gameContent.GameActivity"
        android:configChanges="orientation|screenSize"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

The problem is that I get the exception when I run my project:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

What is the proper XML to set the fullscreen theme for this type of activity?


Solution

  • Try putting this in your styles.xml

    <style name="AppTheme.Fullscreen" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>
    

    And then in your manifest

    android:theme="@style/AppTheme.Fullscreen"