I am trying to make a button with a selector, my button may have the following states:
- Enabled / Disabled
- Press / Not Pressed
In accordance with the above conditions. I need to manipulate a button:
- Text color
- background image
The button starts to turn off, so it must have textColor turned off and the background of the button turned off. But I can see the default textColor text (specified in the style) and NO background image!
Here is my button_selector.xml selector
<?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>
And here is the declaration of my button in 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" />
And finally, this is my style (where my textColor text is set)
<?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>
Please, help!
android xml button selector background-image
Nouran H Jun 27 '12 at 11:27 2012-06-27 11:27
source share