zoukankan      html  css  js  c++  java
  • ImageView切换两种状态下的模式

    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

  • 相关阅读:
    软件开发模式
    个人中心设计
    定制四则运算
    功能测试用例分析报告
    NABCD
    开发流程
    开发流程
    结对编程
    注册界面进行Toast提示
    登录注册页面修改错误
  • 原文地址:https://www.cnblogs.com/xingyyy/p/5218529.html
Copyright © 2011-2022 走看看