Friday, December 30, 2016

Customizing an Android Button - Changing Font Color on Click?

Do you need to change the color of the text when a button is clicked? 
To do so, create a selector resource in res/color directory for the text color 
custom_text_color.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/colorTextIcons" android:state_pressed="true" />
    <item android:color="@color/colorPrimaryDark" android:state_pressed="false" />
</selector>
Then add the color to the button layout:
 <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    android:textColor="@color/custom_text_color"
    />