<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 默认时的背景图片-->
<item android:drawable="@drawable/pic1" />
<!-- 没有焦点时的背景图片 -->
<item android:state_window_focused="false"
android:drawable="@drawable/pic1" />
<!-- 非触摸模式下获得焦点并单击时的背景图片 -->
<item android:state_focused="true"
android:state_pressed="true"
                android:drawable= "@drawable/pic2" />
<!-- 触摸模式下单击时的背景图片-->
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/pic3" />
<!--选中时的图片背景-->
<item android:state_selected="true"
android:drawable="@drawable/pic4" />
<!--获得焦点时的图片背景-->
<item android:state_focused="true"
android:drawable="@drawable/pic5" />
</selector>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 圆角 -->
<corners
android:radius="9dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:bottomRightRadius="2dp"/><!-- 设置圆角半径 --> <!-- 渐变 -->
<gradient
android:startColor="@android:color/white"
android:centerColor="@android:color/black"
android:endColor="@android:color/black"
android:useLevel="true"
android:angle="45"
android:type="radial"
android:centerX="0"
android:centerY="0"
android:gradientRadius="90"/> <!-- 间隔 -->
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/><!-- 各方向的间隔 --> <!-- 大小 -->
<size
android:width="50dp"
android:height="50dp"/><!-- 宽度和高度 --> <!-- 填充 -->
<solid
android:color="@android:color/white"/><!-- 填充的颜色 --> <!-- 描边 -->
<stroke
android:width="2dp"
android:color="@android:color/black"
android:dashWidth="1dp"
android:dashGap="2dp"/> </shape>

state_selected="true"  选中状态

shape  设置形状,可以在selector,layout等里面使用,有6个子标签

填充:设置填充的颜色

间隔:设置四个方向上的间隔

大小:设置大小

圆角:同时设置五个属性,则Radius属性无效

android:Radius="20dp"                           设置四个角的半径

android:topLeftRadius="20dp"              设置左上角的半径
android:topRightRadius="20dp"           设置右上角的半径
android:bottomLeftRadius="20dp"      设置右下角的半径
android:bottomRightRadius="20dp"    设置左下角的半径

描边:dashWidth和dashGap属性,只要其中一个设置为0dp,则边框为实现边框

android:width="20dp"                               设置边边的宽度
android:color="@android:color/black"  设置边边的颜色
android:dashWidth="2dp"                         设置虚线的宽度
android:dashGap="20dp"                          设置虚线的间隔宽度

渐变:当设置填充颜色后,无渐变效果。angle的值必须是45的倍数(包括0),仅在type="linear"有效,不然会报错。android:useLevel 这个属性不知道有什么用。

angle对应值的起点如图:

android 背景选择器的更多相关文章

  1. android背景选择器selector用法汇总

    一.创建xml文件,位置:drawable/xxx.xml,同目录下记得要放相关图片 <?xml version="1.0" encoding="utf-8&quo ...

  2. 【Android】Android背景选择器selector用法汇总

    一.创建xml文件,位置:drawable/xxx.xml,同目录下记得要放相关图片 <?xml version="1.0" encoding="utf-8&quo ...

  3. android selector 背景选择器的使用, button (未点击,点击,选中保持状态)效果实现

              android selector 背景选择器的使用, button (未点击,点击,选中保持状态)效果实现 首先看到selector的属性: android:state_focus ...

  4. Android:关于背景选择器Selector的item顺序

    在使用背景选择器的时候,如果item的顺序不对,会导致不起作用. 1.首先背景选择器的normal选项一定要放在最后. 2.pressed的选择器应该在seclet的前面.我在使用的时候找了半天问题, ...

  5. Android中selector背景选择器

    http://blog.csdn.net/forsta/article/details/26148403 http://blog.csdn.net/wswqiang/article/details/6 ...

  6. Android View 背景选择器编写技巧

    在项目中选择器的使用是非常多的,以下是本人在项目中的一些常用的背景选择器的写法 带边框下划线背景选择器效果图: 上面布局中放了10个CheckBox,然后设置了CheckBox的背景图片位,背景选择器 ...

  7. 【原创】Android selector选择器无效或无法正常显示的一点研究

    想将LinearLayout作为一个按钮,加上一个动态背景,按下的时候,背景变色,这个理所当然应该使用selector背景选择器来做: <LinearLayout android:id=&quo ...

  8. Android文件选择器的实例分享

    本文给大家讲解下Android文件选择器的使用.实际上就是获取用户在SD卡中选择的文件或文件夹的路径,这很像C#中的OpenFileDialog控件. 此实例的实现过程很简单,这样可以让大家快速的熟悉 ...

  9. 第01讲- Android背景知识

    第01讲Android背景知识 Android是基于Linux系统 Android系统框图 : 第一.操作系统层(OS) 第二.各种库(Libraries)和Android 运行环境(RunTime) ...

随机推荐

  1. Java-selenium

    public class chrometest { public static void main(String[] args) throws InterruptedException { Strin ...

  2. 推荐算法之用矩阵分解做协调过滤——LFM模型

    隐语义模型(Latent factor model,以下简称LFM),是推荐系统领域上广泛使用的算法.它将矩阵分解应用于推荐算法推到了新的高度,在推荐算法历史上留下了光辉灿烂的一笔.本文将对 LFM ...

  3. 用例图浅谈以及OOA再到情景分析的面向对象电梯的设计(慕课东北大学)面向对象设计思维模式

    上班初期还不太适应,平时学习进度也跟不上,节奏慢下来会有时间更新的了. Diagram  这边以学生课程报名系统为例    这就是一种简单的用例图 用例图可以给读者提供的信息非常丰富,但是缺点是都是概 ...

  4. 十一、设备初始化(ADK4.0)

    1.1     首先初始化连接库 sinkConnectionInit();à ConnectionInitEx2();  theCm.task.handler = connectionBluesta ...

  5. 使用idea来部署git项目

    使用idea来部署git项目 一).将项目交由git管理 VCS ---->import into Version Cntorl ------>create Git Repository ...

  6. react antd Table动态合并单元格

    示例数据 原始数组 const data = [ { key: '0', name: 'John Brown', age:22, address: 'New York No. 1 Lake Park' ...

  7. 2019-9-18:渗透测试,基础学习,ubuntu搭建LNMP,phpmyadmin

    1,安装nginx:sudo apt-get install nginx 2,安装完成,输入,service nginx start开启服务,输入:netstat -ntulp |grep 80,确定 ...

  8. C语言与汇编语言混合编程实验

    混合编程方法: 模块链接法 汇编指令嵌入法 1: 模块链接法则 模块链接法是指分别用汇编语言和C语言实现独立的模块(或子程序),再用链接程序把各模块生成的obj文件连接成一个可执行程序. 1:C语言调 ...

  9. Stream系列(三) FlatMap方法使用

    将多维嵌套列表转换为单维列表 EmployeeTestCase.java package com.example.demo; import lombok.Data; import lombok.ToS ...

  10. Spring(Bean)2

    <!-- util:list封装的心 --> <bean id="personList2" class="spring.beans.di.collect ...