简体   繁体   中英

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

<activity
    android:name="com.luckyxmobile.timers4meplus.activity.WidgetConfigActivity"
    android:theme="@style/Theme.PageIndicator.Dark">
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />

        <category android:name="com.jakewharton.android.viewpagerindicator.sample.SAMPLE" />
    </intent-filter>
</activity>


<style name="Theme.PageIndicator.Dark" parent="android:Theme">
    <item name="tpi_tabPadding">12dp</item>
    <item name="tpi_tabRipple">@style/DarkTabRippleStyle</item>
    <item name="tpi_indicatorHeight">3dp</item>
    <item name="tpi_indicatorColor">@color/colorPrimary</item>
    <item name="android:textAppearance">@style/DarkTabTextAppearance</item>
    <item name="android:background">@color/colorAccent</item>
    <item name="tpi_mode">scroll</item>
</style>

The above is theme and style.When I run the app,show this error. I think maybe it should be "Theme.AppCompat" not "android:Theme",but not sure!

Whats your logcat throws

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

I guess, you need to extends AppCompatActivity

public class WidgetConfigActivity extends AppCompatActivity {
  // ...
}

AppCompatActivity is from the appcompat-v7 library. Principally, this offers a backport of the action bar. Since the native action bar was added in API Level 11, you do not need AppCompatActivity for that. However, current versions of appcompat-v7 also add a limited backport of the Material Design aesthetic, in terms of the action bar and various widgets.

You can use Theme.AppCompat instead of android:Theme .

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