繁体   English   中英

错误:java.lang.IllegalStateException:您需要在此活动中使用Theme.AppCompat主题(或后代)

[英]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>

以上是主题和样式。当我运行应用程序时,显示此错误。 我认为可能应该是“ Theme.AppCompat”而不是“ android:Theme”,但不确定!

你的logcat抛出了什么

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

我想,您需要扩展AppCompatActivity

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

AppCompatActivity来自appcompat-v7库。 原则上,这提供了操作栏的反向移植。 由于本机操作栏是在API级别11中添加的,因此您不需要AppCompatActivity。 但是,就动作栏和各种小部件而言,当前版本的appcompat-v7还增加了有限的Material Design美学支持。

您可以使用Theme.AppCompat代替android:Theme

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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