Android(安卓)selector背景选择器 用法汇总
学习自:http://wenku.baidu.com/view/c49040728e9951e79b8927e2.html
作用:可以根据控件的状态来变换背景状态(比如,一个按钮,选中时,按钮变成另外一张图片)。
用法:创建xml文件,位置:drawable/xxx.xml,
<?xml version="1.0" encoding="utf-8"?>
相关属性解释:
android:state_focused 是获得焦点
android:state_pressed 是点击android:state_selected 是选中 (选中=活的焦点+点击)
android:state_enabled 是设置是否响应时间,指所有事件
使用xml文件:
a.xml中: ListView 的 android:listSelector="@drawable/xxx"
或ListView的item里面 android:background="@drawable/xxx"
b.代码中: Drawable drawable = getResources().getDrawable(R.drawable.xxx);
listView.setSelector(drawable);此时可能会出现列表黑的情况,
加上android:cacheColorHint="@android:color/transparent"使其透明。
selector中shape的使用 学习自:http://kofi1122.blog.51cto.com/2815761/521605
作用:可以实现按钮的绘制,比如button的 圆角,渐变,边框的绘制。
相关属性解释: solid: 实心,就是填充的意思
android:color 指定填充的颜色
gradient: 渐变
android:startColor和android:endColor分别为起始和结束颜色,android:angle是渐变角度,必须为45的整数倍
android:type="linear" 默认为线性渐变,可以指定渐变为径向渐变,type="radial",需指定半径android:gradientRadius="50"
stroke:描边
android:width="2dp" 描边的宽度android:color="red" 描边的颜色
描边也可以设置为虚线的形式,
android:dashWidth="5dp" 表示"-"这样一个横线的宽度
android:dashGap="3dp" 表示之间隔开的距离
corners: 圆角
android:radius 角的弧度,值越大角越圆还可以设置
android:topRightRadius="20dp" 右上角
android:bottomLeftRadius="20dp" 右下角
android:topLeftRadius="1dp" 左上角
android:bottomRightRadius="0dp" 左下角
selector的混合使用 :
-
-
Demo下载:http://download.csdn.net/detail/u012524598/7410755
更多相关文章
- android 导入项目报错
- android:shape的使用
- android selector 背景选择器的使用, button (未点击,点击,选中保持
- Android中shape中的属性大全
- 【Android应用】【Shape使用总结】
- android:shape的使用
- Android(安卓)PureMVC
- android shape用法(xml文件)
- android 图片相关处理