[英]Android: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
I still got a crash report because of this Exception 由于出现此异常,我仍然收到崩溃报告
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I have searched about it, still can't figure it out how to fix this. 我已经搜索过它了,但仍然不知道如何解决。
I have using Theme.AppCompat.Light as base AppTheme. 我已经使用Theme.AppCompat.Light作为基本AppTheme。 Here my style.xml 这是我的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>
I only have 1 style.xml inside values folder 我在values文件夹中只有1个style.xml
I'm using crashlytics in my app, I got this problem only from some device, but this is really annoys me. 我在我的应用程序中使用了crashlytics,仅从某些设备上遇到了此问题,但这确实让我很烦。
Is there anyone know hot to fix this? 有谁知道热解决这个问题?
I have done both of things below, but still got a crash report. 我已完成以下两项操作,但仍收到崩溃报告。
You are getting this problem because you have derived one or more of your Activity
classes from ActionBarActivity
. 之所以出现此问题,是因为您从ActionBarActivity
派生了一个或多个Activity
类。 You need to either derive from Activity
OR you need to use one of the Theme.Appcompat
styles for your ActionBar
. 您需要从Activity
派生, 或者需要为ActionBar
使用Theme.Appcompat
样式之一。 And make sure you specify the correct android:theme
attribute in all your <activity ... />
declarations in your manifest. 并确保在清单中的所有<activity ... />
声明中指定正确的android:theme
属性。
EDIT: 编辑:
Add android:theme="@style/AppTheme"
to the declaration of MainActivity
in your app manifest. 将android:theme="@style/AppTheme"
到应用清单中的MainActivity
声明中。 And change parent="Theme.AppCompat.Light"
to parent="@style/Theme.AppCompat.Light"
in res/theme.xml
. 并在res/theme.xml
parent="Theme.AppCompat.Light"
更改为parent="@style/Theme.AppCompat.Light"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.