Android – Button with text color changed on click

This is the easiest way to make a button with text color changing on press like in the following screenshot:

Not pressed and pressed states of the button

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:text="Great button"
        android:textColor="@color/selector_button"
        />

Make a color selector xml and put it in the res/color folder.
The xml should look like this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#2277AA" />
    <item android:color="#8697A4"/>
</selector>

Leave a Reply

You must be logged in to post a comment.