[英]How to change the background color of the action bar in Android?
I was working hard to achieve this but I had no luck. 我正在努力实现这一目标,但是我没有运气。 What I tried to do is to change the background color from the style that I attached in my main style tag.
我试图做的是从主样式标签中附加的样式更改背景颜色。 This is my code:
这是我的代码:
<resources>
<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item ></item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#2E495E</item>
</style>
Still nothing changed. 仍然没有改变。 I get this in my application:
我在我的应用程序中得到了这个:
http://i.imgur.com/m1MrGwk.png http://i.imgur.com/m1MrGwk.png
I had the same issue and it's probably the same problem you were having. 我遇到了相同的问题,可能是您遇到的相同问题。 Notice the docs say the following:
注意文档说以下内容:
each style property that you declare must be declared twice..
您声明的每个样式属性必须声明两次。
So my issue was I declared it for 2.1 and up, but not for 3.0 and greater so my Galaxy S4 of course could not see any changes to the colours I was making. 因此,我的问题是我声明其适用于2.1及更高版本,而不适用于3.0及更高版本,因此我的Galaxy S4当然看不到我所做的颜色的任何更改。
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<!--Support Library compatibility-->
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">@color/green</item>
<!--Support Library compatibility-->
<item name="background">@color/green</item>
</style>
<style name="NoActionBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
Is this the only style.xml you have?
这是您唯一的style.xml吗? Else check if you are modifying for the right API
否则检查您是否正在修改正确的API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.