在res/drawable文件夹新增一个文件,此文件设置了图片的触发状态,你可以设置 state_pressed,state_checked,state_pressed,state_selected,state_focused,state_enabled 等几个状态:

android:state_pressed

Boolean. "true" if this item should be used when the object is pressed (such as when a button is touched/clicked); "false" if this item should be used in the default, non-pressed state.

如果是true,当被点击时显示该图片,如果是false没被按下时显示默认。

android:state_focused

Boolean. "true" if this item should be used when the object is focused (such as when a button is highlighted using the trackball/d-pad); "false" if this item should be used in the default, non-focused state.

true,获得焦点时显示;false,没获得焦点显示默认。

android:state_selected

Boolean. "true" if this item should be used when the object is selected (such as when a tab is opened); "false" if this item should be used when the object is not selected.

true,当被选择时显示该图片;false,当未被选择时显示该图片。

android:state_checkable

Boolean. "true" if this item should be used when the object is checkable; "false" if this item should be used when the object is not checkable. (Only useful if the object can transition between a checkable and non-checkable widget.)

true,当CheckBox能使用时显示该图片;false,当CheckBox不能使用时显示该图片。

android:state_checked

Boolean. "true" if this item should be used when the object is checked; "false" if it should be used when the object is un-checked.

true,当CheckBox选中时显示该图片;false,当CheckBox为未选中时显示该图片。

android:state_enabled

Boolean. "true" if this item should be used when the object is enabled (capable of receiving touch/click events); "false" if it should be used when the object is disabled.

true,当该组件能使用时显示该图片;false,当该组件不能使用时显示该图片。

android:state_window_focused

Boolean. "true" if this item should be used when the application window has focus (the application is in the foreground), "false" if this item should be used when the application window does not have focus (for example, if the notification shade is pulled down or a dialog appears).

true,当此activity获得焦点在最前面时显示该图片;false,当没在最前面时显示该图片。

<?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/button_pressed"/><!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@drawable/button_focused"/><!-- focused -->
    <itemandroid:drawable="@drawable/button_normal"/><!-- default -->

</selector>

selector 的用法,在选择和不选择情况下的颜色的更多相关文章

  1. ios 地图,系统升级为12后,进入地图,大头针全部默认展开问题,以及在选择不同距离的情况下,如何刷新地图的区域范围

    1.第一个问题,大头针在ios12,默认展开问题,需要设置大头针视图的默认选中属性为NO - (MKAnnotationView *)mapView:(MKMapView *)mapView view ...

  2. Selector API用法

    java.nio.channels 类 Selector java.lang.Object java.nio.channels.Selector 直接已知子类: AbstractSelector pu ...

  3. Android菜鸟成长记9 -- selector的用法

    在项目开发的时候,由于系统给出的控件不够美观,因此开发时领导常常要我更改下界面,用美工给的图片取代系统图片.开始时,我只是给按钮等设置一下背景图片,这样做虽然美观了,但界面看起来却比较死板,比如用户点 ...

  4. CSS选择符-----元素选择符

       通配选择符(*)           选定所有对象 通配选择符(Universal Selector) 通常不建议使用通配选择符,因为它会遍历并命中文档中所有的元素,出于性能考虑,需酌情使用 & ...

  5. Sql Server优化之索引提示----我们为什么需要查询提示,Sql Server默认情况下优化策略选择的不足

    环境: Sql Server2012 SP3企业版,Windows Server2008 标准版 问题由来: 最近在做DB优化的时候,发现一个存储过程有非常严重的性能问题, 由于整个SP整体逻辑是一个 ...

  6. Pandas之容易让人混淆的行选择和列选择

    在刚学Pandas时,行选择和列选择非常容易混淆,在这里进行一下讨论和归纳 本文的数据来源:https://github.com/fivethirtyeight/data/tree/master/fa ...

  7. 选择Android还是选择JavaEE?

    很多同学咨询过同样的一个问题,该问题也是最备受争议的问题,那就是到底是选择Android还是选择JavaEE.下面发表一些本人的看法.       Android属于一个特有的Java技术应用,专注于 ...

  8. SEL数据类型,@selector的用法,以及调用SEL

    1.SEL数据类型 SEL是个指针类型的数据,类似C语言中的函数指针.在OC中,每个对象方法都有其对应着一个SEL变量.当我们调用对象方法时,编译器会将该方法转换成一个SEL的数据,然后去类中寻找该方 ...

  9. JS-加载页面的时候自动选择刚才所选择option

    <body class="no-skin" onload="option_auto(${pd.PACK_SORT})"> <select na ...

随机推荐

  1. 你可能不知道console强大

    写在前面 大家都有用过各种类型的浏览器,每种浏览器都有自己的特色,本人拙见,在我用过的浏览器当中,我是最喜欢Chrome的,因为它对于调试脚本及前端设计调试都有它比其它浏览器有过之而无不及的地方.可能 ...

  2. C#学习系列-类与结构的区别

    参考:http://www.microsoftvirtualacademy.com/Content/ViewContent.aspx?et=9851&m=9830&ct=31038 如 ...

  3. salesforce 零基础学习(三十六)通过Process Builder以及Apex代码实现锁定记录( Lock Record)

    上一篇内容是通过Process Builder和Approval Processes实现锁定记录的功能,有的时候,往往锁定一条记录需要很多的限制条件,如果通过Approval Processes的条件 ...

  4. c#动态调用Webservices

    方式一: Hashtable ht = new Hashtable(); ht.Add("a", "testhelloworld"); XmlDocument ...

  5. DOM_06之定时器、事件、cookie

    1.定时器:①任务函数:函数结尾判断临界值:②启动定时器:a.周期性:timer=setInterval(任务函数,interval):b.一次性:timer=setTimeout(任务函数,wait ...

  6. 1.安装Redis

    首要条件:安装VMware,在虚拟机中安装CentOS. 安装步骤: 1.打开终端(Terminal) 2.在终端输入:wget http://download.redis.io/releases/r ...

  7. SQL Server 2012 T-SQL 新特性

    序列 Sequence SQL Server 现在将序列当成一个对象来实现,创建一个序列的例子语法如下: CREATE SEQUENCE DemoSequence START WITH 1 INCRE ...

  8. SSIS连接SAPBI

        SSIS默认的连接管理器是没有连接到Oracle或SAPBI的,因此如果希望SSIS调用SAP RFC的话,可以使用微软提供的连接管理器插件.     有关这一点的详细信息可以参考MSDN的官 ...

  9. JUnit4使用

    1.导入Junit4jar包: Eclipse中在项目上右键点击Bulid Path,然后再点击Add libraries,选择JUnit 2.初次使用 首先先创建一个java项目如下: Demo.j ...

  10. hdu3635 Dragon Balls(带权并查集)

    /* 题意:有N个城市, 每一个城市都有一个龙珠(编号与城市的编号相同),有两个操作 T A ,B 将标号为A龙珠所在城市的所有的龙珠移动到B龙珠所在城市中! 思路:并查集 (压缩路径的时候将龙珠移动 ...