Atlas91
Atlas91

Reputation: 5904

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

I try to use a custom theme using the AppCompat in this way

<resources>
    <style name="Theme.AppCompat" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="android:windowContentOverlay">@null</item>
        <!--<item name="android:homeAsUpIndicator">@drawable/ic_drawer</item>--> 
        <item name="android:actionOverflowButtonStyle">@style/Theme.AppCompat.OverFlow</item>
  </style>

  <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
      <item name="android:background">#00bcd4</item>
      <item name="android:windowContentOverlay">@null</item>
  </style>

    <style name="Theme.AppCompat.OverFlow">
     <item name="android:src">@drawable/menu</item>
  </style>

</resources>

When i start the application i get this error:

10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.app.ActivityThread.access$800(ActivityThread.java:144)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.os.Handler.dispatchMessage(Handler.java:102)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.os.Looper.loop(Looper.java:135)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.app.ActivityThread.main(ActivityThread.java:5221)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at java.lang.reflect.Method.invoke(Native Method)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at java.lang.reflect.Method.invoke(Method.java:372)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
10-23 16:43:09.595: E/AndroidRuntime(27301): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at com.ee.newapp.MainActivity.onCreate(MainActivity.java:53)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.app.Activity.performCreate(Activity.java:5933)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
10-23 16:43:09.595: E/AndroidRuntime(27301):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
10-23 16:43:09.595: E/AndroidRuntime(27301):    ... 10 more

and in the manifest i wrote: android:theme="@style/Theme.AppCompat"

Any idea why could crashes? Thanks

Upvotes: 0

Views: 551

Answers (1)

MrEngineer13
MrEngineer13

Reputation: 38856

Your logcat tells you everything

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

So instead of

@android:style/Theme.Holo.Light

Use this as your parent theme

Theme.AppCompat.Light

Upvotes: 3

Related Questions