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

Asked

Viewed 726 times

1

Good afternoon ! I’m creating a styleGuides for an android application and I’m having difficulty changing the color of the button text at the moment it is clicked by the user: In this example I am creating a block of the cancel button, where initially the color of the text is red, the text is cancel (style) and when pressing it receives a change in the edges and its background changes to red (drawable) and it is at that time that I need the color of the text also change, in this case to WHITE, follows codes mentioned: 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 is only missing is to change the color of the text to the button to be clicked, I would like to do this via XML even to be able to use as default library for the App. If you have any improvement tips I’ll be happy to know!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.