1.目标效果

在选中和未选中的过程中,切换展示图片

2.实现方法

(1)在app--->res--->drawable

右击drawable文件夹右键,new ---->drawable resource file

注意:生成的xml文件必须在drawable目录下,而不是在drawable(v24)包下。

(2)编写xml文件

实例:selector_nextbtn_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--选中用深绿色的图-->
<item android:state_pressed="true" android:drawable="@drawable/function_greenbutton_pressed"></item>
<!--未选中用浅绿色的图-->
<item android:drawable="@drawable/function_greenbutton_normal"></item>
</selector>

(3)图片选择器的使用

往往通过设置控件的 android:background 属性。

<Button
android:text="下一页"
android:background="@drawable/selector_nextbtn_bg"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

3.效果图

观察按钮颜色的变化。

参考文献:https://developer.android.google.cn/guide/topics/resources/drawable-resource#StateList

最新文章

  1. Asp.net 面向接口可扩展框架之核心容器(含测试代码下载)
  2. 网络性能测试工具iperf详细使用图文教程【转载】
  3. 从模态视图push到另一个视图
  4. Java的别名机制
  5. centos、linux改变ll命令显示颜色
  6. android源码编译常见错误
  7. 查看某一个点是否在某个多边形内 使用ST_Contains函数
  8. Quick Tip: Outline Elements on Hover
  9. 中国科学院信息project研究所 第四研究室实习生/应届生招聘
  10. 【第一篇】Volley的使用之json请求
  11. 模型的元数据Meta -- Django从入门到精通系列教程
  12. Convert.ToInt32、(int)和int.Parse三者的区别
  13. Android开发:文本控件详解——EditText(一)基本属性
  14. dos.orm的事务处理
  15. 使用PIA查找组件的PeopleSoft导航
  16. Redis数据类型使用场景及有序集合SortedSet底层实现详解
  17. 带你入门Python爬虫,8个常用爬虫技巧盘点
  18. HappenBefore
  19. ALGO-12_蓝桥杯_算法训练_幂方分解(递归)
  20. 控制台API函数----HANDLE、SetConsoleCursorPosition、SetConsoleTextAttribute

热门文章

  1. UOJ#397. 【NOI2018】情报中心 线段树合并 虚树
  2. Note_4.7
  3. 小程序中怎么引入wepy.js第三方toast组件
  4. [RK3399] ES8316+NS4150 播放视频只有背景音,播放歌曲有的有声音,有的无声音
  5. postgresql【二】postgresql强制删除数据库
  6. CENTOS7安装OPENSSL
  7. elasticsearch 的入门
  8. face morhper
  9. MiniUI表单验证总结
  10. python try except 出现异常时,except 中如何返回异常的信息字符串