[英]How can I change the color of the Android Action Bar?
I am trying to change the color of my Android ActionBar, but my app is closing with an error each time. 我正在尝试更改Android ActionBar的颜色,但是我的应用每次关闭均出现错误。 I have tried all other suggestions and fixes in other posts, but they dont seem to work for me.
我在其他帖子中尝试了所有其他建议和修复,但它们似乎对我没有用。 Also - minSdkVersion 19
另外-minSdkVersion 19
Error: 错误:
03-17 11:25:56.884 11999-11999/ca.holdfastonline.menu_test_02 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: ca.holdfastonline.menu_test_02, PID: 11999
java.lang.RuntimeException: Unable to start activity ComponentInfo{ca.holdfastonline.menu_test_02/ca.holdfastonline.menu_test_02.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
My Styles.xml 我的Styles.xml
<resources>
<style name="QueryTheme" parent="@style/Theme.AppCompat">
<!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#2980b9</item>
</style>
</resources>
My AndroidManifest.xml 我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ca.holdfastonline.menu_test_02" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/QueryTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thank you. 谢谢。
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
You have only one activity. 您只有一项活动。 It is using
@style/CustomActionBarTheme
. 它使用
@style/CustomActionBarTheme
。 Your definition of CustomActionBarTheme
has it inheriting from Theme.Holo.Light.DarkActionBar
. 您对
CustomActionBarTheme
定义继承自Theme.Holo.Light.DarkActionBar
。 That is not an AppCompat
theme. 这不是
AppCompat
主题。 Change Theme.Holo.Light.DarkActionBar
to Theme.AppCompat.Light.DarkActionBar
. 更改
Theme.Holo.Light.DarkActionBar
到Theme.AppCompat.Light.DarkActionBar
。
This is probably because in your Java file you are using ActionBarActivity and you should be using Activity. 这可能是因为在Java文件中,您正在使用ActionBarActivity,而您应该在使用Activity。
More Info Basically you are using ActionBarActivity, this activity requires a Theme.AppCompact which is where your error is coming from. 更多信息基本上,您正在使用ActionBarActivity,此活动需要一个Theme.AppCompact,这是您的错误出处。 To fix this you would need to change to use the regular Activity or just use Theme.AppCompact
要解决此问题,您需要更改为使用常规的Activity或仅使用Theme.AppCompact
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.