在imageview中,我们把两张不同颜色的相同图片放入drawable,创建xml文件
xml文件编写:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/huadonganniu2"/>
<item android:state_selected="false" android:drawable="@drawable/huadonganniu1"/>
</selector>
drawable中写自己放在drawable图片中的名称
在存放控件的xml文件中,在引用图片的地方引用上方的xml文件
true的时候写按下的时候呈现的图片
activity的编写:
imageview.setSelected(true);
imageview为自己点击的控件