android 开发中 对于 shape 和 selector的使用,一直都不是很熟练, 记录一下.便于以后参考.

举个项目中例子图

对于上面的2个radiobutton ,背景我们可以让美工做一个.9图来实现. 但是最后还是自己用shape 搞一下.

按钮布局如下:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_8"
android:orientation="horizontal"> <RadioGroup
android:id="@+id/order_rg"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="@dimen/space_8"
android:layout_marginRight="@dimen/space_8"
android:orientation="horizontal">
       //默认选中
<RadioButton
android:id="@+id/rb_left"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_weight="1"
android:background="@drawable/fg_order_rb_selector"
android:button="@android:color/transparent"
android:checked="true"
android:drawablePadding="@dimen/space_4"
android:gravity="center"
android:text="投资记录"
android:textColor="@drawable/fg_order_text_selector"
android:textSize="@dimen/txt_14" />
       //默认不选中
<RadioButton
android:id="@+id/rb_right"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_weight="1"
android:background="@drawable/fg_order_rb_selector1"
android:button="@null"
android:drawablePadding="@dimen/space_4" android:text="提现记录"
android:gravity="center"
android:textColor="@drawable/fg_order_text_selector"
android:textSize="@dimen/txt_14" />
</RadioGroup>
</LinearLayout>

里面用到2个 selector ,   1个是文字背景选择器fg_order_text_selector,1个RadioButton颜色背景选择器fg_order_rb_selector1

2个RadioButton用到的文字选择器如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white" android:state_checked="true"/> //白色
<item android:color="@color/black" android:state_checked="false"/>//黑色
</selector>

第一个RadioButton用到的颜色背景选择器   :fg_order_rb_selector.xml  , rb_left.xml , rb_right.xml  如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/rb_left"
android:state_checked="true"
android:state_enabled="true"
/> <item
android:drawable="@drawable/rb_right"
android:state_checked="false"
android:state_enabled="false"/>
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 圆角 -->
<corners android:bottomLeftRadius="6dp" android:topLeftRadius="6dp" />
<stroke android:color="@color/wave_bg" android:width="1dp" />
<!--内部填充色-->
<solid android:color="@color/wave_bg" />
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 圆角 -->
<corners android:bottomLeftRadius="6dp" android:topLeftRadius="6dp" /> <stroke android:color="@color/wave_bg" android:width="1dp" />
<!--内部填充色-->
<solid android:color="@color/white"/>
</shape>

第二个RadioButton用到的颜色背景选择器   :fg_order_rb_selector1.xml  , rb_left1.xml , rb_right1.xml  如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/rb_left1"
android:state_checked="true"
android:state_enabled="true"
/> <item
android:drawable="@drawable/rb_right1"
android:state_checked="false"
android:state_enabled="false"/>
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 圆角 -->
<corners android:bottomRightRadius="6dp" android:topRightRadius="6dp" /> <stroke android:color="@color/wave_bg" android:width="1dp" />
<!--内部填充色-->
<solid android:color="@color/wave_bg" />
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 圆角 -->
<corners android:bottomRightRadius="6dp" android:topRightRadius="6dp" /> <stroke android:color="@color/wave_bg" android:width="1dp" />
<!--内部填充色-->
<solid android:color="@color/white"/>
</shape>

以上就是 全部资源文件了. 没有用到任何一张图.

参考博文:http://blog.csdn.net/zzy7075/article/details/42235947

android中shape 的使用的更多相关文章

  1. Android中shape属性详解

    一.简单使用 刚开始,就先不讲一堆标签的意义及用法,先简单看看shape标签怎么用. 1.新建shape文件 首先在res/drawable文件夹下,新建一个文件,命名为:shape_radius.x ...

  2. 【Android 界面效果19】Android中shape的使用

    Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结: 先看下面的代码:         <shape>      ...

  3. Android 中 shape 图形的使用

    转载于:http://kofi1122.blog.51cto.com/2815761/521605 Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shap ...

  4. Android 中shape的使用(圆角矩形)

    一.在res/drawable文件夹下创建一个名为gradient_box的xml文件: <?xml version="1.0" encoding="utf-8&q ...

  5. 转 Android中shape中的属性大全

    <shape>            <!-- 实心 -->            <solid android:color="#ff9d77"/&g ...

  6. Android中shape中的属性大全

    ---恢复内容开始--- <shape> <!-- 实心 --> <solid android:color="#ff9d77"/> <!- ...

  7. android中shape的属性

    <shape> <!– 实心 –> <solid android:color=”#ff9d77″/> <!– 渐变 –> <gradient an ...

  8. Android中shape的使用 (转载)

    转自:http://blog.csdn.net/ekeuy/article/details/12349853 在看很多开源代码中都使用到了shape,我看代码的时候一般都一带而过了,没有仔细去研究,这 ...

  9. android中shape的使用(android:angle小解)

    本文参考http://kofi1122.blog.51cto.com/2815761/521605和http://blog.csdn.net/qizi329/article/details/63098 ...

随机推荐

  1. 什么是HTML,HTML的简介,HTML结构

    html:超文本标记语言(Hyper Text Markup Language) ==============基本结构================= <html><!--最外层为 ...

  2. 帝国CMS(EmpireCMS) v7.5后台getshell分析(CVE-2018-18086)

    帝国CMS(EmpireCMS) v7.5后台getshell分析(CVE-2018-18086) 一.漏洞描述 EmpireCMS 7.5版本及之前版本在后台备份数据库时,未对数据库表名做验证,通过 ...

  3. WIN10家庭版桌面右键单击显示设置出现ms-settings:display或ms-settings:personalization-background解决办法[原创]

    最近,笔者的笔记本卸载oracle数据库,注册表里面删除了不少相关信息,没想到担心的事情还是来了!桌面右键单击显示设置出现ms-settings:display或ms-settings:persona ...

  4. 报error:getNetworkFromStore for nid failed while trying to build sandbox for cleanup: network

    docker服务起不来.报error:getNetworkFromStore for nid failed while trying to build sandbox for cleanup: net ...

  5. Unity经典案例之:Fire Balls 多个圆环以及圆环的变速变向

    版权申明: 本文原创首发于以下网站: 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123 优梦创客的官方博客:https://91make.top ...

  6. python学习笔记(2)--列表、元组、字符串、字典、集合、文件、字符编码

    本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1.列表和元组的操作 列表是我们以后最长用的数据类型之一,通过列表可以最方便的对数据实现最方便的存储.修改等操作 定 ...

  7. 小白系统篇-windows 系统安装

    现阶段装系统的方法基本有几种1.硬盘安装2.光驱安装3.PE(u盘即可)安装 现在比较主流方便的用pe安装,所以我们这边就说一下PE安装系统的方法 首先我们了解下系统镜像,也就是你装系统所需得到文件( ...

  8. com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect

    com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: con ...

  9. 关于post和get的区别

    首先,get和post并没有本质上的区别,都只是 HTTP 协议中两种请求方式,用的都是同一个传输层协议,在传输上并没有什么不同.     1.get和post报文上的区别 GET 和 POST 只是 ...

  10. javaScript 基础知识汇总(三)

    1.循环:while 和 for while 循环 while(condition){ //代码 循环体 } do ... while  循环 let i =0; do { //循环体 }while( ...