-2

I know that this question has been asked before, but the provided answers did not solve my case, so I'll ask for an individual solution.

My code

My AndroidManifest.xml looks like this:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".KategorieAuswahl"
        android:label="@string/title_activity_kategorie_auswahl" >
    </activity>
    <activity
        android:name=".ZeigeFragen"
        android:label="@string/title_activity_zeige_fragen" >
    </activity>
</application>

And my styles.xml looks like this:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>
</resources>

I want my App to open in fullscreen and to hide the TitleBar. The first thing I did was to add a android:theme="@android:style/Theme.NoTitleBar.Fullscreen" attribute to the <application>-Tag of my AndroidManifest.xml.

This leads to the error You need to use a Theme.AppCompat theme (or descendant) with this activity. Here is the full stacktrace:

05-27 21:24:26.889    2121-2121/de.test.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{de.test.myapp/de.test.myapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:113)
            at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
            at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
            at de.test.myapp.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

There are multiple questions on stackoverflow referencing this error.


Approach #1

One solution suggests to change the Java inheritance from ActionBarActivity to Activity and leave the manifest as it is.

So I updated my the <style> element in my styles.xml and removed the DarkActionBar part:

<style name="AppTheme" parent="Theme.AppCompat.Light">

This still gives me the same error.


Approach #2

The next solution suggests to change my styles.xml's parent attribute from

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

to <style name="AppTheme" parent="Theme.AppCompat">

This makes it possible to use android:theme="@style/Theme.AppCompat.NoActionBar" for my <activity>, but I don't see an option to make it fullscreen then.


Approach #3

Another solution soggests to add <item name="android:windowNoTitle">true</item> to my <style> element but this doesn't change anything at all.


Conclusion

I really tried a lot, but nothing seems to work. Anyway I have problems understanding the theme inheritance chain and when I may use .NoTitleBar and .Fullscreen.

After all I don't care which theme to use, as long I can make the app fullscreen without a title bar. Can you help me to pick the right attributes?

Community
  • 1
  • 1
YMMD
  • 3,730
  • 2
  • 32
  • 43

1 Answers1

0

extend ActionBarActivity or the new one, and use Theme.AppCompat.NoActionBar, now in your Activity

if (Build.VERSION.SDK_INT < 16) {
    Activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
}else{
    Activity.getWindow().getDecorView().
            setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);              
}

Hope it helps..

Elltz
  • 10,730
  • 4
  • 31
  • 59