[英]Android Button selector not working properly
I am using the following selector to change the color of a button 我正在使用以下选择器更改按钮的颜色
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@color/darkgray" />
<item android:state_enabled="true" android:state_pressed="true" android:drawable="@color/background_red_down" />
<item android:drawable="@color/background_red" />
</selector>
I am getting the red color for the button but that's it. 我将按钮变成红色,仅此而已。 I am not getting the gray disabled color, the button is indeed disabled as it is unclickable. 我没有得到灰色的禁用颜色,该按钮的确是禁用的,因为它不可单击。 I am also not getting the red_down color once I click. 单击后,我也没有得到red_down颜色。
What have I missed? 我错过了什么?
Thanks 谢谢
This is code from my button selector. 这是我的按钮选择器中的代码。 Modify it's values and it should work for you. 修改它的值,它应该对您有用。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/redtheme_btn_default_normal_holo_light" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="@drawable/redtheme_btn_default_disabled_holo_light" />
<item android:state_pressed="true"
android:drawable="@drawable/redtheme_btn_default_pressed_holo_light" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/redtheme_btn_default_focused_holo_light" />
<item android:state_enabled="true"
android:drawable="@drawable/redtheme_btn_default_normal_holo_light" />
<item android:state_focused="true"
android:drawable="@drawable/redtheme_btn_default_disabled_focused_holo_light" />
<item
android:drawable="@drawable/redtheme_btn_default_disabled_holo_light" />
</selector>
in your color.xml 在你的color.xml中
replace this 取代这个
<color name="background_red">#9A9484</color>
to 至
<drawable name="background_red">#9A9484</drawable>
" #9A9484 = your background color " “ #9A9484 =您的背景色 ”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.