崩溃与自定义主题android引起:java.lang.IllegalStateException:您需要使用Theme.AppCompat主题(或后代)与此活动

时间:2014-10-23 14:49:33

标签: java android android-theme android-appcompat

我尝试以这种方式使用AppCompat使用自定义主题

<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>

当我启动应用程序时,我收到此错误:

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

并在清单中写道:android:theme="@style/Theme.AppCompat"

知道为什么会崩溃?感谢

1 个答案:

答案 0 :(得分:3)

您的logcat告诉您所有内容

  

您需要在此活动中使用Theme.AppCompat主题(或后代)。

所以而不是

@android:style/Theme.Holo.Light

将此作为您的父主题

Theme.AppCompat.Light