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 ...
随机推荐
- 安装tensorflow-gpu出现的问题
1.Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/l ...
- A - Mike and Cellphone
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was n ...
- apk重签名的两种方法
因为robotium要求被测应用和测试代码要有一致的签名, 所以需要将apk包重签名. 方法一:通过re-sign.jar来产生debug key的apk(不适用于jdk 7以上) re-sign.j ...
- Flutter实战视频-移动电商-64.会员中心_顶部头像UI布局
64.会员中心_顶部头像UI布局 会员中心的样式 member.dart 清除原来的代码生成一个基本的结构 默认返回一个scaffold脚手架工具,body里面布局使用ListView,这样不会出现纵 ...
- Identity Server 4 原理和实战(完结)_Authorization Code Flow 实例
Code在Oauth2.0和OpenId Connect里面分别叫做不同的名字 OAuth只介绍了如何授权.没有介绍如何身份认证. OpenId Connect:既规定了怎么授权,也规定了怎么身份认证 ...
- Git小白到老鸟的进阶之路
点"计算机视觉life"关注,置顶更快接收消息! 小白:师兄,师兄,上次你教我的操作,我傻乎乎的执行了一遍,可是那个Git究竟是什么那? 师兄:小白莫慌,Git就是一种版本控制,小 ...
- 地理位置(navigation.geolocation)与本地存储(seessionStorage、localStorage)
一.地理位置( geolocation ): navigator.geolocation对象: 1.单次请求: //navigator.geolocation.getCurrentPosition( ...
- php 发送邮件(实例)
html部分 <!DOCTYPE html> <html> <head> <title></title> <script type=& ...
- Unity mesh 合并
簡介: 基本上就是把 很多物體結合成一個物體 的作法,這種做法有很多優點,例如:1. 提高效能2. 統一材質 (只要建立一個材質,就能控制.分配給所有物體)3. 動畫控制方便 (像是你要在 Unity ...
- unity 引入 android第三方sdk
unity中调用java代码中介绍了unity调用android java代码的一些基础.引入android开发第三方sdk的操作跟调用java代码的操作相似,只是多了一步引入第三方jar. unit ...