在res/drawable文件夹新增一个文件,此文件设置了图片的触发状态,你可以设置 state_pressed,state_checked,state_pressed,state_selected,state_focused,state_enabled 等几个状态:
< selector xmlns:android="http://schemas.android.com/apk/res/android">< item android:state_pressed="true" android:drawable="@drawable/arrow_pressed" />< item android:drawable="@drawable/arrow_normal" />< item android:state_checked="true" android:drawable="@drawable/arrow_pressed" />< /selector>
其中的android:src="@drawable/imageselector"
< ImageView
android:layout_width="wrap_content"
android:layout_height="@android:dimen/app_icon_size"
android:layout_alignParentRight="true"
android:scaleType="fitCenter"
android:layout_gravity="center"
android:src="@drawable/imageselector"
android:clickable="true"
android:focusable="true"
android:id="@+id/blacklistImageView"
android:layout_marginRight="10dip" />//如果当触发的控件不是ImageView,而是别的控件,可在代码中用blacklistImageView.setPressed(true);blacklistImageView.setChecked(true);