Android中selector背景选择器
来源:互联网 发布:redis和mysql结合使用 编辑:程序博客网 时间:2024/04/30 08:22
转至:http://blog.csdn.net/forsta/article/details/26148403
在Android开发过程中,经常对某一View的背景在不同的状态下,设置不同的背景,增强用户体验。如果按钮,在按下时,背景变化,如果在代码中动态设置,相对比较麻烦。Android为我们提供了selector背景选择器可以非常方便的解决这一问题。
Selector的结构描述:
1.android:state_pressed="true/false"
true:表示按下状态下使用,false:表示非按下状态下使用。
2.android:state_focused="true/false"
ture:表示聚焦状态使用(例如使用滚动球/D-pad聚焦Button),false:表示非聚集状态下使用。
3.android:state_selected="true/false"
true:表示被选中状态下使用,false:表示非选中下使用
4.android:state_active="true/false"
true:表示可勾选状态时使用,false:表示不可勾选状态下使用
5. android:state_checkable="true/false"
true:表示勾选状态下使用,false:表示非勾选状态使用
6.android:state_checked="true/false"
true:表示勾选状态下使用,false:表示非勾选状态使用
7. android:state_enabled="true/false"
true:表示可用状态使用(能接收触摸/点击事件),false:表示不可用状态使用
8. android:state_window_focused="true/false"
true:表示应用程序窗口有焦点时使用(应用程序在前台),false:表示无焦点时使用
9.android:background
设置背景图片 模拟灯开启关闭
在drawable目录先新建bg_button.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android">
- <item android:state_checked="true" android:drawable="@drawable/r7"></item>
- <item android:state_checked="false" android:drawable="@drawable/r7b"></item>
- </selector>
为了方便点击查看效果 使用CheckBox组件
- <CheckBox
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:button="@null"
- android:textSize="15sp"
- android:textColor="#EE2C2C"
- android:drawableTop="@drawable/bg_button"
- android:text="灯"/>
效果:
- Android中selector背景选择器
- Android中selector背景选择器
- Android中selector背景选择器
- android selector 背景选择器
- android背景选择器selector
- android selector背景选择器
- android 背景选择器selector
- android背景选择器selector
- Android-selector背景选择器
- Android背景选择器selector
- android selector背景选择器
- Android Selector 背景选择器
- android的selector,背景选择器
- android的selector,背景选择器
- Android的selector,背景选择器
- Android 的 selector--背景选择器
- Android的selector,背景选择器
- android背景选择器selector用法
- Android事件分发机制研究
- Eclipse主题修改,换个颜色换个心情撸代码吧
- Linux下Hadoop集群的搭建(3)—集群模式
- Matlab中传递函数的表示和计算_20151222
- 性能测试
- Android中selector背景选择器
- uva 11714——Blind Sorting
- 缓存分级
- unity3d 之 边缘光(rim)
- C++学习笔记36——赋值操作符
- FragmentTransaction的add(),hide(),show()方法与Replace()方法的比较
- Java常用类和方法重点总结
- 三、为solr配置mmseg4j中文分词
- 修改unity GI cache位置