简体   繁体   中英

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

I still got a crash report because of this Exception

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

I have searched about it, still can't figure it out how to fix this.

I have using Theme.AppCompat.Light as base AppTheme. Here my style.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/toolbar</item>
    <item name="colorPrimaryDark">@color/toolbar_dark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="actionOverflowButtonStyle">@style/OverFlow</item>
    <item name="searchViewStyle">@style/ActionBarSearchView</item>
    <item name="colorControlActivated">@color/switch_activated</item>
    <item name="colorSwitchThumbNormal">@color/switch_normal</item>
    <item name="android:colorForeground">@color/switch_track</item>
</style>

I only have 1 style.xml inside values folder

I'm using crashlytics in my app, I got this problem only from some device, but this is really annoys me.

Is there anyone know hot to fix this?

I have done both of things below, but still got a crash report.

You are getting this problem because you have derived one or more of your Activity classes from ActionBarActivity . You need to either derive from Activity OR you need to use one of the Theme.Appcompat styles for your ActionBar . And make sure you specify the correct android:theme attribute in all your <activity ... /> declarations in your manifest.

EDIT:

Add android:theme="@style/AppTheme" to the declaration of MainActivity in your app manifest. And change parent="Theme.AppCompat.Light" to parent="@style/Theme.AppCompat.Light" in res/theme.xml .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM