我试图使一个选择器按钮,我的按钮可以有以下状态:
根据上面提到的状态。我需要操作按钮的:
The button starts off my being disabled so it should have the disabled textColor and the disabled button background. But I can see the default textColor (specified in style) and NO background image!
下面是我的选择器 Button _ selector. xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:state_enabled="false"
android:textColor="#9D9FA2"
android:drawable="@drawable/button" />
<item android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/button_pressed"/>
<item android:state_pressed="true"
android:state_enabled="false"
android:textColor="#9D9FA2"
android:drawable="@drawable/button"/>
<item android:state_pressed="false"
android:state_enabled="true"
android:drawable="@drawable/button"/>
</selector>
这是 my layout.xml 中的按钮声明
<Button android:id="@+id/reserve_button"
android:text="@string/reserve_button"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:paddingRight="15dp"
android:layout_gravity="left"
style="@style/buttonStyle"
android:background="@drawable/button_selector" />
最后,这是我的样式(其中设置了默认 textColor)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="buttonStyle">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#282780</item>
<item name="android:textSize">18sp</item>
</style>
</resources>
救命啊!