java.lang.IllegalStateException:您需要在此活动中使用 Theme.AppCompat 主题(或后代)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21331836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
提问by user3231849
I'm getting this error when trying to run my android application.
尝试运行我的 android 应用程序时出现此错误。
The strange thing: It only happens when the android application was built (and signed) with Jenkins.
奇怪的是:它只发生在 android 应用程序是用 Jenkins 构建(并签名)时。
When I use the local apk file from eclipse and push it to my device (or emulator), everything works fine
当我使用来自 eclipse 的本地 apk 文件并将其推送到我的设备(或模拟器)时,一切正常
Any ideas?
有任何想法吗?
Edit: AndroidManifest.xml
编辑:AndroidManifest.xml
<application
android:name="at.my.test.App"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyActionBarTheme" >
<activity
android:name="SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="LoginActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="MyFirstActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="MySecondActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="MyThirdActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="WebActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="ErrorActivity"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar" >
</activity>
</application>
And the themes.xml file:
和 themes.xml 文件:
<style name="MyActionBarTheme" parent="@style/Theme.AppCompat">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:homeAsUpIndicator">@drawable/ic_up_arrow</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowContentOverlay">@null</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="homeAsUpIndicator">@drawable/ic_up_arrow</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:background">@color/my_highlight</item>
<!-- Support library compatibility -->
<item name="background">@color/my_highlight</item>
</style>
回答by ASP
May this will help you to solve your problem. (I haven't familiar with Jenkins.) Please put this attribute to Activity (in which you used the Actionbar/Drawer) in Manifest
愿这将帮助您解决您的问题。(我对 Jenkins 不熟悉。)请将此属性放在 Manifest 中的 Activity(其中您使用了 Actionbar/Drawer)
android:theme="@style/Theme.AppCompat"
回答by saneryee
styles.xml
样式文件
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
回答by Mahendran Candy
This is happen only for missing styles from values-21,values-18 missing in resource folder in android project or you are not used to declared the correct theme in Manifest in appropriate project.
这仅发生在 android 项目的资源文件夹中缺少 values-21、values-18 中的样式,或者您不习惯在相应项目的 Manifest 中声明正确的主题。