1

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.

Ye Myat Min
  • 1,429
  • 2
  • 17
  • 29

2 Answers2

2

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 - Android selector & text color

Community
  • 1
  • 1
Ye Myat Min
  • 1,429
  • 2
  • 17
  • 29
0

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
  • 198,401
  • 62
  • 356
  • 264
  • 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. – Ye Myat Min Jul 04 '10 at 06:29