码迷,mamicode.com
首页 > 其他好文 > 详细

ImageView切换两种状态下的模式

时间:2016-02-25 22:58:56      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:

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>

 切换图片

1 //深色
2 likeIcon.setSelected(true);
3 //浅色
4 likeIcon.setSelected(false);

Done

ImageView切换两种状态下的模式

标签:

原文地址:http://www.cnblogs.com/xingyyy/p/5218529.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!