簡體   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