繁体   English   中英

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

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

由于出现此异常,我仍然收到崩溃报告

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

我已经搜索过它了,但仍然不知道如何解决。

我已经使用Theme.AppCompat.Light作为基本AppTheme。 这是我的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>

我在values文件夹中只有1个style.xml

我在我的应用程序中使用了crashlytics,仅从某些设备上遇到了此问题,但这确实让我很烦。

有谁知道热解决这个问题?

我已完成以下两项操作,但仍收到崩溃报告。

之所以出现此问题,是因为您从ActionBarActivity派生了一个或多个Activity类。 您需要从Activity派生, 或者需要为ActionBar使用Theme.Appcompat样式之一。 并确保在清单中的所有<activity ... />声明中指定正确的android:theme属性。

编辑:

android:theme="@style/AppTheme"到应用清单中的MainActivity声明中。 并在res/theme.xml parent="Theme.AppCompat.Light"更改为parent="@style/Theme.AppCompat.Light"

暂无
暂无

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

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