您的位置:首页 > 其它

ImageView切换两种状态下的模式

2016-02-25 21:45 274 查看
1、xml对ImageView的src要设置成selector

<ImageView
android:id="@+id/like_icon"
android:layout_width="@dimen/will_like_icon_width"
android:layout_height="@dimen/will_like_icon_height"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:src="@drawable/selector" />


drawable/selector.xml

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


切换图片

//深色
likeIcon.setSelected(true);
//浅色
likeIcon.setSelected(false);


Done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: