更改动作条按钮的背景颜色时,pressed [英] Change actionbar button background color when pressed
问题描述
如果我preSS操作栏中的按钮,那么它的背景颜色是不是我想要的。我的项目的背景颜色不回应我的单击事件。我怎样才能改变这一点,改变背景颜色,当它是pressed?
If I press a button in the action bar, then its background color is not what I want. The background color of my item doesn't respond to my click event. How can I change this and change the background color when it's pressed?
推荐答案
您需要声明<一个href="http://developer.android.com/reference/android/R.attr.html#actionBarItemBackground"><$c$c>android:actionBarItemBackground$c$c>属性是一个:
You need to declare android:actionBarItemBackground
attribute which is a:
自定义项状态列表绘制背景的动作栏项目。
Custom item state list drawable background for action bar items.
然后,在你的风格操作步骤如下:
Then, in your styles do as follows:
<style name="CustomStyle" parent="@style/Theme.Holo.Light" >
<item name="android:actionBarItemBackground">@drawable/ab_item_background</item>
<item name="actionBarItemBackground">@drawable/ab_item_background</item>
</style>
所以,把你自己的绘制与选择
和每个州(pressed,突出重点,残疾人等)有预期的背景。例如,绘制 ab_item_background.xml
宣布上述可能是这样的:
So, put your own drawable with a selector
and every state (pressed, focused, disabled, etc) to have the expected background. For example, the drawable ab_item_background.xml
declared above might be like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<!-- focused/pressed: color=red -->
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@color/red" />
<!-- pressed: color=red -->
<item
android:state_pressed="true"
android:drawable="@color/red" />
<!-- normal: color=transparent -->
<item
android:drawable="@android:color/transparent" />
</selector>
在造型的操作栏,你可以找到所有的定制符合候选条件和所有的属性这样做。
In Styling the Action Bar, you can find all the customization possibles and all the attributes to do so.
这篇关于更改动作条按钮的背景颜色时,pressed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!