您的位置:首页 > 移动开发 > Android开发

selector.xml(选择器)

2015-11-22 22:26 369 查看
配置位置

在drawable中配置

作用

根据配置的状态来使用相应的背景图片

例子

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/pic1"
android:state_window_focused="false"/>
</selector>


其中
android:drawable=""
为图片索引;
android:state_window_focused="false"
为显示条件

<!--选中-->
android:state_selected
<!--获得焦点-->
android:state_focused
<!--点击-->
android:pressed
<!--设置响应事件-->
android:state_enabled
......


配置完后在layout中的使用

在相应的控件中加入
android:background="@drawable/XXX_selector"


<selector>


中的属性:

-
xmlns:android="http://schemas.android.com/apk/res/android"
命名空间,值必须为给定地址

-
android:android:constantSize=["true" | "false"]
若为“true”则所有状态中的图片大小等同于状态中最大图片的大小,为“false”则基于原大小,默认为“false”

-
android:dither=["true" | "false"]
处理屏显颜色问题,不做游戏不深究了。

-
android:variablePadding
“true”当状态被选中时图片padding改变,默认为“false”
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android