Hi, I am implementing something like the user interface from Microsoft Zune HD player. So, I would like to change the text color of my button when the button is being pressed as well as when it has been clicked.
A:
In res/drawable, create a file called for instance mybutton_background.xml
and put something like this inside:
<?xml version="1.0" encoding="utf-8"?>
<selector android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false"
android:drawable="@drawable/button_background_focus" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/button_background_pressed" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/button_background_pressed" />
<item drawable="@drawable/button_background_normal">
</selector>
Then set this drawable as the background of your button with android:background="@drawable/mybutton_background"
.
Cristian
2010-07-04 05:43:17
Actually, I am trying to change the text color but not the background as my background shall stay black no matter what state it is in.
2010-07-04 06:29:14
A:
Case solved. I just added an XML file into my color folder. Add in a selector XML and change the attribute "textColor" of my button to that selector XML.
Further reference - http://goo.gl/Oqnn.