I made a button that changes the background drawable on different states, this way:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/btn_location_pressed" /> <!-- pressed -->
<item android:state_focused="true" android:drawable="@drawable/btn_location_pressed"/> <!-- focused -->
<item android:drawable="@drawable/btn_location"/> <!-- default -->
The problem here is that I'm also trying to change the textColor as I do with the drawable but I'm not being able to. I already tried android:textColor and android:color but the first doesn't work whilst the seconds changes my background.
The next code is part of my layout. Regarding to the text color it only works for the normal state text color, thus not changing it to the white one while pressed
<Button android:id="@+id/location_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:background="@drawable/location"
android:textSize="15sp"
android:textColor="@color/location_color"
android:textColorHighlight="#FFFFFF"
/>
Has anybody got a clue?
Another way to do it is in your class:
Changing text color of button
Because this method is now deprecated
I use the following:
ok very simple first go to 1. res-valuse and open colors.xml 2.copy 1 of the defined text their for example #FF4081 and change name for instance i changed to white and change its value for instance i changed to #FFFFFF for white value like this
then inside your button add this line
ok b3 is the name of my button so changed of the name of ur button all others will be same if u use white color if you change different color then change white to the name of your color but first you have define that color in colors.xml like i explained in pont 2
Create a stateful color for your button, just like you did for background, for example:
Place the xml in a file at res/drawable folder i.e. res/drawable/button_text_color.xml. Then just set the drawable as text color: