I attach the XML code that I use as the background of my button:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<stroke android:width="1dp"
android:color="#ffffff"/>
<corners android:radius="20dp"/>
</shape>
</item>
<item android:state_pressed="false">
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
<corners android:radius="20dp"/>
</shape>
</item>
</selector>
This code only changes the background of my button when pressed, but the font color stays the same.
What I want to achieve is to change both the background color and the text color of my button.
Thank you for reading!
In this case you would have to create another selector which would be set to your button:
the selector must be created inside
res/color
, here you can reference colors defined insidecolors.xml
.texto_selector.xml
: