Android selector背景选择器
selector根据不同的选定状态来定义不同的现实效果
常用属性:
- android:state_selected--------选中
- android:state_focused--------获得焦点
- android:state_pressed--------点击
- android:state_enabled--------设置是否响应事件
- android:drawable 放一个drawable资源
- android:state_pressed 是否按下,如一个按钮触摸或者点击。
- android:state_focused 是否取得焦点,比如用户选择了一个文本框。
- android:state_hovered 光标是否悬停,通常与focused state相同,它是4.0的新特性
- android:state_selected 被选中,它与focus state并不完全一样,如一个list view 被选中的时候,它里面的各个子组件可能通过方向键,被选中了。
- android:state_checkable 组件是否能被check。如:RadioButton是可以被check的。
- android:state_checked 被checked了,如:一个RadioButton可以被check了。
- android:state_enabled 能够接受触摸或者点击事件
- android:state_activated 被激活(这个麻烦举个例子,不是特明白)
- android:state_window_focused 应用程序是否在前台,当有通知栏被拉下来或者一个对话框弹出的时候应用程序就不在前台了
有的需要加android:focusable和android:clickable为true才能获取焦点
简单实例:点击按钮改变样式

按钮:
<Button
android:layout_width="160dp"
android:layout_height="wrap_content"
android:background="@drawable/button_select"
android:text="点我变色"
/>
button_select.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/play_button"></item>
<item android:state_focused="true" android:drawable="@drawable/play_button"></item>
<item android:drawable="@drawable/button"></item>
</selector>
button.xml默认效果
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#E53B36"/>
</shape>
play_button.xml点击效果
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#E8B714"/>
</shape>
常用checkbox设置:
<?xml version="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/btn_check_on" />
<item android:state_window_focused="false" android:state_enabled="true" android:state_checked="false" android:drawable="@drawable/btn_check_off" />
<item android:state_enabled="true" android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/btn_check_on_pressed" />
<item android:state_enabled="true" android:state_checked="false" android:state_pressed="true" android:drawable="@drawable/btn_check_off_pressed" />
<item android:state_focused="true" android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/btn_check_on_selected" />
<item android:state_focused="true" android:state_enabled="true" android:state_checked="false" android:drawable="@drawable/btn_check_off_selected" />
<item android:state_enabled="true" android:state_checked="false" android:drawable="@drawable/btn_check_off" />
<item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/btn_check_on" />
</selector>
常用ImageButton设置:
<?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/button2_down" />
<item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/button2_over" />
<item android:state_enabled="true" android:drawable="@drawable/button2" />
</selector>
常用Button设置:
<?xml version="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/login_input" />
<item android:state_pressed="true" android:drawable="@drawable/login_input" />
<item android:state_focused="true" android:drawable="@drawable/input_over" />
</selector>
设置TextView
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:color="@color/gray" android:state_pressed="false" android:state_enabled="true"/>
<item android:color="@color/white" android:state_pressed="true" android:state_enabled="true"/>
<item android:color="@color/gray" android:state_enabled="false"/></selector>
Android selector背景选择器的更多相关文章
- android selector 背景选择器的使用, button (未点击,点击,选中保持状态)效果实现
android selector 背景选择器的使用, button (未点击,点击,选中保持状态)效果实现 首先看到selector的属性: android:state_focus ...
- Android——selector背景选择器的使用详解(二)
在开发应用中,很多情况下要设计listview或button控件的背景,下面总结一下android的selector的用法:1.在drawable中配置Android的selector.将如下的XML ...
- Android中selector背景选择器
http://blog.csdn.net/forsta/article/details/26148403 http://blog.csdn.net/wswqiang/article/details/6 ...
- Android:关于背景选择器Selector的item顺序
在使用背景选择器的时候,如果item的顺序不对,会导致不起作用. 1.首先背景选择器的normal选项一定要放在最后. 2.pressed的选择器应该在seclet的前面.我在使用的时候找了半天问题, ...
- Android View 背景选择器编写技巧
在项目中选择器的使用是非常多的,以下是本人在项目中的一些常用的背景选择器的写法 带边框下划线背景选择器效果图: 上面布局中放了10个CheckBox,然后设置了CheckBox的背景图片位,背景选择器 ...
- android中的selector背景选择器的用法
关于listview和button都要改变android原来控件的背景,在网上查找了一些资料不是很全,所以现在总结一下android的selector的用法. 首先android的selector是在 ...
- Android的selector 背景选择器
关于listview和button都要改变android原来控件的背景,在网上查找了一些资料不是很全,所以现在总结一下android的selector的用法.首先android的selector是在d ...
- [转]永久告别Android的背景选择器Selector!无需切很多图了!
package com.zoke.custom.autobg; import android.content.Context; import android.content.res.TypedArra ...
- Android:res之selector背景选择器
selector根据不同的选定状态来定义不同的现实效果 常用属性: android:state_selected--------选中android:state_focused--------获得焦点a ...
随机推荐
- iOS使用自己定义字体
1.加入相应的字体(.ttf或.odf)到project的resurce,比如my.ttf. 2.在info.plist中加入一项 Fonts provided by application (ite ...
- BZOJ 4216 Pig 分块乱搞
题意:id=4216">链接 方法:分块以节约空间. 解析: 这题坑的地方就是他仅仅有3M的内存限制,假设我们开longlong前缀和是必死的. 所以考虑缩小这个long long数组 ...
- JavaScript 匹配浮点数
//匹配整数,正小数 appUtils.bindEvent($(_pageId+" .remind-list-con input"),function(){ var reg = / ...
- Oracle 字符串不为空条件
Oracle 中,空字符串存入到Oracle中会自动转换为NULL,另外VARCHAR2把空串等同于null处理. SQL from dual where null=null; 没有查到记录 SQL ...
- scikit-learn---PCA(Principle Component Analysis)---KNN(image classifier)
摘要:PCA为非监督分类方法,常用于数据降维.为监督分类数据预处理,本例采用PCA对人脸特征提取先做降维处理,然后使用KNN算法对图片进行分类 ##1.PCA简介 设法将原来变量重新组合成一组新的互相 ...
- vim 窗口管理
一.切分窗口 1. 水平切分 命令::sp file 快捷键:<Ctrl-W> + S 2. 垂直切分 命令: :vsp file 快捷键:<Ctrl-W> + V 二.关 ...
- Python内置函数之str()
class str(object="")class str(object=b'', encoding='utf-8', errors='strict') 将其他对象转化为字符串对象 ...
- junit测试时报No runnable methods错误的解决方法
1.因为你@Test时import的是@org.testng.annotations.Test所以会报错 解决方法:改为import org.junit.Test;就可以了
- Exploiting CVE-2015-2509 /MS15-100 : Windows Media Center could allow remote code execution
Exploiting CVE-2015-2509 /MS15-100 : Windows Media Center could allow remote code execution Trend Mi ...
- [译]GLUT教程 - 移动镜头3
Lighthouse3d.com >> GLUT Tutorial >> Input >> Moving the Camera III 上一节的示例中我们用键盘更改 ...