Androidにはボタン画像が1つしかありませんが、選択された効果と選択されていない効果を作成するにはどうすればよいですか?

1. セレクターを定義します。

drawaber ディレクトリに、新しいセレクター ファイルを作成します。

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