Android只有一张按钮图,怎么做出选中与非选中效果?

1.定义一个selector:

在drawaber目录下,新建selector文件:

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>

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是图片。

选中和非选中

选中:原图:

猜你喜欢

转载自blog.csdn.net/howlaa/article/details/129420031