Android中的Selector的使用总结
Android中的Selector主要是用来改变ListView和Button控件等其他空的默认背景,其使用方法可以如下所示:
1、首先在res目录下drawable文件夹,新建一个comm_button_bg.xml的xml文件。
2、编辑comm_button_bg.xml文件,其代码结构如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
<!-- 触摸模式下单击时的背景图片-->
<item android:drawable="@drawable/btn_bg_pressed" android:state_pressed="true"></item>
<item android:drawable="@drawable/btn_bg_normal" android:state_pressed="false"></item> <!-- 非触摸模式下获得焦点并单击时的背景图片 -->
</selector>
3、可以根据项目需求自定义自己想要的样式,如下所示:
设置选择按钮按下以及不按下的 文字颜色变化效果 textColor
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--设置点击的时候,控件的文本颜色--->
<item android:color="@android:color/white" android:state_pressed="true"></item>
<item android:color="@android:color/black" android:state_pressed="false"></item>
</selector>
类似的属性还可以为:
android:state_selected选中
android:state_focused获得焦点
android:state_pressed点击
android:state_enabled设置是否响应事件,指所有事件
4、在布局文件中 使用comm_button_bg.xml定义好的样式
<Button
android:background="@drawable/common_button_bg" <!----使用自定义好的样式----->
android:text="测试"
android:textColor="@drawable/common_button_textcolor_selector"
android:textSize="20sp" />
Android中的Selector的使用总结的更多相关文章
- Android中的Selector的用法
转自: Android中的Selector主要是用来改变ListView和Button控件的默认背景.其使用方法可以按一下步骤来设计: (以在mylist_view.xml为例) 1.创建mylist ...
- android中的selector背景选择器的用法
关于listview和button都要改变android原来控件的背景,在网上查找了一些资料不是很全,所以现在总结一下android的selector的用法. 首先android的selector是在 ...
- Android中的selector
android背景选择器selector用法汇总 (2011-04-19 13:40:00) 转载▼ 标签: android selector 背景选择器 it 分类: java/vb/Android ...
- Android 中的selector
今天做程序时,发现了selector 选择器不单单能用系统的自定义属性(比如, <item android:state_selected="true" android:co ...
- 转:Android中的Selector的用法
http://blog.csdn.net/shakespeare001/article/details/7788400
- Android中Selector的用法(改变ListView和Button的默认背景)
Android中的Selector的用法 http://blog.csdn.net/shakespeare001/article/details/7788400#comments Android中的S ...
- android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用
android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用,只要把Imageview的src给去掉就成了,src捕获了bac ...
- Android中selector的使用
第一种方法(强烈推荐) 方法:selector做遮罩,原图做background. 我们做按钮的时候经常需要用两个图片来实现按钮点击和普通状态的样式,这就需要提供两种图片,而且每个分辨率下还有多套图片 ...
- 【转】 Android中selector的使用
引言 selector中文的意思选择器,在Android中常常用来作组件的背景,这样做的好处是省去了用代码控制实现组件在不同状态下不同的背景颜色或图片的变换.使用十分方便. selector的定义 s ...
随机推荐
- 激活层和pooling的作用
激活层: 激活函数其中一个重要的作用是加入非线性因素的,将特征映射到高维的非线性区间进行解释,解决线性模型所不能解决的问题 pooling层: 1. invariance(不变性),这种不变性包括tr ...
- 算法实现c语言--01
打印九九乘法表 #include<stdio.h> #include<stdlib.h> int main() { , j = ; ; i <= ; i++) { ; j ...
- centos7使用ceph-deploy部署ceph
准备阶段 准备yum源 删除默认的源,国外的比较慢 yum clean all rm -rf /etc/yum.repos.d/*.repo 下载阿里云的base源 wget -O /etc/yum. ...
- hibernate 学习 一 基本概念
1: Hibernate对JDBC进行封装,以面向对象的方式对关系型数据库进行操作. 2: Hibernate的配置文件: hibernate.properties 或者 hibernate.c ...
- JS获取元素的offsetTop,offsetLeft等相关属性
1. obj.clientWidth //获取元素的宽度 obj.clientHeight //元素的高度 obj.offsetLeft //元素相对于父元素的left obj.offsetTop / ...
- CodeForces 1103E. Radix sum
题目简述:对任意两个(正)十进制数$a = \overline{a_{k-1}\dots a_1a_0}$和$b = \overline{b_{k-1}\dots b_1b_0}$,定义其[十进制按位 ...
- A. Launch of Collider (#363 Div.2)
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- androidEditTextinputType及android:imeOptions=”actionDone”(转)
一.android 软件盘事件响应 在android中,有时需要对EditText实现软件盘监听的场景.当android按下软键盘的时候,响应完成.发送.搜索或者其他事件. Google 提供了 Ed ...
- SQL——基础概念
服务器登录名:指有权限登录到某服务器的用户:如sa 服务器角色:指一组固定的服务器用户,默认有9组: 登录名一定属于某些角色,默认为public 服务器角色不容许更改 登录后也不一定有权限操作数据库 ...
- SmartSql使用教程(1)——初探,建立一个简单的CURD接口服务
一.引言 最近SmartSql被正式引入到了NCC,借着这个契机写一个使用教程系列 二.SmartSql简介[摘自官方文档] 1. SmartSql是什么? SmartSql = MyBatis + ...