http://gundumw100.iteye.com/blog/1146527

 
上面这种3选1的效果如何做呢?用代码写? 
其实有更简单的办法,忘了RadioButton有什么特性了吗? 
我就用RadioButton实现了如上效果,其实很简单的。 
首先定义一张background,命名为radio.xml,注意该background必须为xml样式的图片:

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

这里我们只要关心state_checked状态就可以了。所以很简单的配置。 
接下来就是布局文件里面引用这张图片了:

 

 <RadioGroup  

        android:gravity="center"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RadioButton
android:id="@+id/btn_0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="最新信息"
android:textSize="17.0sp"
android:textColor="@android:color/black"
android:gravity="center"
android:layout_weight="1"
android:checked="true"
android:button="@null"
android:background="@drawable/radio"
/>
<RadioButton
android:id="@+id/btn_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="在线专家"
android:textSize="17.0sp"
android:textColor="@android:color/black"
android:gravity="center"
android:layout_weight="1"
android:button="@null"
android:background="@drawable/radio"
/>
<RadioButton
android:id="@+id/btn_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="预约服务"
android:textSize="17.0sp"
android:textColor="@android:color/black"
android:gravity="center"
android:layout_weight="1"
android:button="@null"
android:background="@drawable/radio"
/>
</RadioGroup>

注意将android:button="@null"全部设为null,并且将android:background="@drawable/radio"设为刚才新建的图片。这样就完成了。 
一句代码都不用写!

看看竖下来的效果: 

傍边有图标的怎么办?

 
也很简单啦,只要在每个RadioButton上加android:drawableLeft="@drawable/tubiao_0"就可以了。 
另外要设置图标与文字的距离怎么办? 
有一个方法setCompoundDrawablePadding(pad)可以设置图标与文字的距离,对应的属性为android:drawablePadding。

有了这招完全可以实现类似的n选1效果,看下面: 
 

应用: 
http://www.iteye.com/topic/1116261#2256664 

转:android 自定义RadioButton样式的更多相关文章

  1. Android 自定义RadioButton样式

     上面这种3选1的效果如何做呢?用代码写? 其实有更简单的办法,忘了RadioButton有什么特性了吗? 我就用RadioButton实现了如上效果,其实很简单的. 首先定义一张background ...

  2. android自定义radiobutton样式文字颜色随选中状态而改变

    主要是写一个 color selector 在res/建一个文件夹取名color res/color/color_radiobutton.xml <selector xmlns:android= ...

  3. Android 自定义RadioButton的样式

    Android 自定义RadioButton的样式 我们知道Android控件里的button,listview可以用xml的样式自定义成自己希望的漂亮样式. 最近用到RadioButton,利用xm ...

  4. Android 自定义RadioButton实现

    由于使用小米系统MIUI运行是RadioButton样式跟google Android API自定义的不一样,则我们可以定义任何想要的东东.没有做不到,只有想不到 Android 自定义RadioBu ...

  5. wpf radiobuttong 去前面的圆点, 自定义radiobutton样式

    自定义radiobutton样式代码: <windows.Resources> <LinearGradientBrush x:Key="CheckRadioFillNorm ...

  6. Android: 自定义Tab样式,一种简单的方式。

    之前看到过论坛里已经有人发过自定义Tab样式的帖子,感觉有些复杂了,这里分享个简单的方法. 1.制作4个9patch的tab样式,可参考android默认的资源 tab_unselected.9.pn ...

  7. 自定义RadioButton样式

    一,在RadioButton标签上使用 android:button="@drawable/pay_radio_selector" 可以修改按钮的样式 二,在RadioButton ...

  8. Android 自定义title样式

    requestWindowFeature(featrueId),它的功能是启用窗体的扩展特性.参数是Window类中定义的常量.一.枚举常量1.DEFAULT_FEATURES:系统默认状态,一般不需 ...

  9. Android自定义ProgressBar样式

    我们使用的进度条多种多样,下面有几种自定义的进度条的样式,下面介绍几个. 进度条的有基本的四种样式: 默认风格的进度条: android:progressBarStyle 水平长型进度条: andro ...

随机推荐

  1. 舍伍德(Sherwood)算法学习笔记

    一.概念引入 设A是一个确定性算法,当它的输入实例为x时所需的计算时间记为tA(x).设Xn是算法A的输入规模为n的实例的全体,则当问题的输入规模为n时,算法A所需的平均时间为.这显然不能排除存在x∈ ...

  2. Nine Great Books about Information Visualization

    Nine Great Books about Information Visualization Maybe it’s anachronistic to celebrate static, print ...

  3. sublime text3入门笔记以及屏蔽sublime自动升级检测更新

    两个月前学习python的时候,有人推荐这个程序员最好用的编辑器,我下载了之后,发现比notepad++要好用很多,目前来说,网上成熟的版本是sublime text2简体中文版,插件也是很兼容,我用 ...

  4. MYSQL的binary解决mysql数据大小写敏感问题 《转载》

    BINARY不是函数,是类型转换运算符,它用来强制它后面的字符串为一个二进制字符串,可以理解为在字符串比较的时候区分大小写如下:mysql> select binary 'ABCD'='abcd ...

  5. QMapControl介绍

    QMapControl是Qt开发的基于LGPL协议开源的显示OpenStreetMap(下简称osm)Tile数据和基于wms-server服务的数据,这里做简单介绍并列出相关资源. QMapCont ...

  6. How to add alias on Mac(It's common for most system)

    Since these files are hidden you will have to do an ls -a to list them. If you don't have one you ca ...

  7. POJ-3580-SuperMemo(splay的各种操作)

    题意:对数组进行各种操作 其中 REVOLVE右移操作.将区间[a,b]右移c位 首先c可能比较多,可以先对区间长度取模. 在右移之后,可以发现[a,b]被分为两个区间[a,b-c]  [b-c+1, ...

  8. (转载)PHP strtotime函数详解

    (转载)http://www.jb51.net/article/21495.htm strtotime函数是一个很好的函数,灵活的运用它,会给你的工作带来不少方便.但PHP的手册中却对此函数的参数没作 ...

  9. Implement Trie (Prefix Tree) ——LeetCode

    Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...

  10. arcgis安装问题SDK开始安装不了

    arcgis安装问题SDK开始安装不了,提示安装Desktop10,安装Desktop10又提示装dotnetfx3.5sp1,最后其实不用这样,可以先把军事扩展包,补丁,安装好,再安装sdk就没有问 ...