Change the text color of a button via XML when clicking on it

1

Good afternoon!   I'm creating a styleGuides for an android application and I'm having a hard time changing the text color of the button to the moment it is clicked by the user:   In this example I'm creating a cancel button, where, initially, the color of the text is red, the text is canceling (style) and when pressed it receives a change in the borders and its background changes to red (drawable) and is at this point I need the text color also change, in this case to WHITE, follow the mentioned codes: Button:

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:background="@drawable/button_cancel"
    style="@style/CancelButton"/>

Style:

<!-- Button Cancel Theme -->
<style name="CancelButton" parent="Base.Widget.AppCompat.Button">
    <item name="android:textColor">@color/colorCancel</item>
    <item name="android:text">Cancelar</item>
    <item name="android:textColorHighlight">#fff</item>
</style>

Drawable (Background):

<?xml version="1.0" encoding="utf-8"?>

                      

        <corners android:radius="3dp" />
        <stroke android:width="2dp" android:color="@color/colorCancel" />
        <solid android:color="@color/colorCancel" />

    </shape>
</item>

</selector>

The way it's only missing is to change the color of the text when the button is clicked, I'd like to do this via XML even so I can use it as a default library for the App. If you have any improvement tips I'll be happy to know! / p>     

asked by anonymous 05.05.2018 / 20:08

0 answers