Search code examples
androidandroid-themeandroid-styles

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!


Solution

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