Android only has one button image, how to make selected and unselected effects?

1. Define a selector:

In the drawaber directory, create a new selector file:

selector_text_template.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_zf_wz_template" android:state_selected="true" />
    <item android:drawable="@drawable/ic_editor_text_template_no_select" android:state_selected="false" />
</selector>

and

ic_editor_text_template_no_select.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:antialias="true"
    android:src="@drawable/ic_zf_wz_template"
    android:tint="@color/com_color_white_40">

</bitmap>
ic_zf_wz_template is the picture.

checked and unchecked

Selected: Original image:

 

Guess you like

Origin blog.csdn.net/howlaa/article/details/129420031