Android
来源:互联网 发布:阿里云实例快照是什么 编辑:程序博客网 时间:2024/06/05 18:25
Android - Selector通过资源文件配置UI属性大全
本篇主要写如何通过资源文件,来配置不同的操作情形下,UI的表现:
1、CheckBox的资源配置
先列出两种不可行的案例:
(1)以下第一种方案,会造成的结果,是未选中的时候,CheckBox会消失
<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 选中-聚焦 --> <item android:drawable="@drawable/checked_select" android:state_checked="true" android:state_enabled="true" android:state_focused="true"></item> <!-- 未选中-聚焦 --> <item android:drawable="@drawable/unchecked_select" android:state_checked="false" android:state_enabled="true" android:state_focused="true"></item> <!-- 已经选中-未聚焦 --> <item android:drawable="@drawable/test" android:state_checked="true" android:state_enabled="true" android:state_window_focused="false"></item> <!-- 未被选中 -未聚焦 --> <item android:drawable="@drawable/test" android:state_checked="false" android:state_enabled="true" android:state_window_focused="false"></item></selector>
(2)以下这种方式,焦点在CheckBox上切换的时候,样式不会改变:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="false" android:state_checked="false" android:drawable="@drawable/unchecked"/> <item android:state_selected="false" android:state_checked="true" android:drawable="@drawable/checked"/> <item android:state_selected="true" android:state_checked="false" android:drawable="@drawable/unchecked_select"/> <item android:state_selected="true" android:state_checked="true" android:drawable="@drawable/checked_select"/> </selector>
(3)经过很久探索,最后发现能够在焦点选中,checked、以及不选时候几种样式之前UI切换的正确配置为
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 这里的样式是有优先级的 第一个item的优先级最高 依次往下推 --> <!-- 选中且有焦点 --> <item android:drawable="@drawable/checked_select" android:state_checked="true" android:state_focused="true"/> <!-- 没有选中但是有焦点 --> <item android:drawable="@drawable/checked" android:state_checked="false" android:state_focused="true"/> <!-- 选中但没有焦点 --> <item android:drawable="@drawable/unchecked" android:state_checked="true" android:state_focused="false"/> <!-- 其他 --> <item android:drawable="@drawable/unchecked_select"/></selector>
2、
阅读全文
0 0
- Android
- android
- Android
- android
- android
- Android
- Android
- android
- android
- android
- Android
- Android
- android!!!
- android
- android
- android
- android
- android:
- (作业)Swift枚举、类、派生、协议
- 【CUGBACM15级BC第36场 A】hdu 5198 Strange Class
- 什么是敏捷过程?
- Spark的Application和依赖的公共jar包单独存放
- JAVA自带的定时器
- Android
- git常用命令
- springmvc自定义异常处理器
- 杂项
- HDU:4004 The Frog's Games<二分>
- 彩色图像和灰色图像的区别
- Extract Numbers
- 【bzoj1057】[ZJOI2007]棋盘制作
- Processes and Application Lifecycle