Reputation: 7472
I am using a selector
to change the background drawable of the button in different states (focused, pressed, normal). Is there any way to change the text color too? I want to provide various text colors for various button states, but I want to do it from the xml. Is this possible?
Upvotes: 4
Views: 20984
Reputation: 724
If it's programmatically, you could use:
Button button = findViewById(R.id.yourbutton);
button.setTextColor(Color.yourcolor);
In xml it'll be the same thing.
Upvotes: 1
Reputation: 50578
Yes it can be done. You just do the same way you do for the button drawable. Then assign it to android:textColor="@drawable/yourselector"
Upvotes: 16
Reputation: 1879
Use android:color="#ff0000"
in selector for focused
and another color for default
state.Then in xml of button android:textColor="@drawable/yourselector"
Upvotes: 0
Reputation: 19733
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#000000" /> <!-- pressed -->
<item android:state_focused="true"
android:color="#000000" /> <!-- focused -->
<item android:color="#FFFFFF" /> <!-- default -->
</selector>
Try combining the above with the android:drawable
attribute.
Upvotes: 11