上面这种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=""
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=""
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=""
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样式

    http://gundumw100.iteye.com/blog/1146527  上面这种3选1的效果如何做呢?用代码写? 其实有更简单的办法,忘了RadioButton有什么特性了吗? 我就用Ra ...

  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. LeetCode 136 Single Number(仅仅出现一次的数字)

    翻译 给定一个整型数组,除了某个元素外其余元素均出现两次. 找出这个仅仅出现一次的元素. 备注: 你的算法应该是一个线性时间复杂度. 你能够不用额外空间来实现它吗? 原文 Given an array ...

  2. opera mini 改服

    opera mini 改服 下载 opera 和 opera mini ftp://ftp.opera.com/pub/opera/android/mini/ ftp://ftp.opera.com/ ...

  3. scrollBarStyle- listview滑动条调整

    今天在解决问题的时候,需要设置listview滚动条,使listview的内容不能被滚动条覆盖 后来发现网上提到一个 ScrollView 属性.ScrollView中ScrollBar的style ...

  4. Android控件开发之Gallery3D效果

    package xiaosi.GalleryFlow; import android.app.Activity; import android.os.Bundle; public class Gall ...

  5. golang passing an array to a function

    package main import “fmt” func fp(a *[]int) { fmt.Println(a) } func main() { ; i < ; i++ { fp(&am ...

  6. Spring源码分析专题 —— IOC容器启动过程(上篇)

    声明 1.建议先阅读<Spring源码分析专题 -- 阅读指引> 2.强烈建议阅读过程中要参照调用过程图,每篇都有其对应的调用过程图 3.写文不易,转载请标明出处 前言 关于 IOC 容器 ...

  7. 用py2exe打包成一个exe文件

    用py2exe打包成一个exe文件 http://blog.csdn.net/franktan2010/article/details/46514607

  8. Linux 网卡驱动学习(九)(层二转发)

    1.mac 地址表的自学习过程 port1上的A计算机要与port2上的B计算机通信时,A发到交换机上,交换机收到信息后,交换机先记录发port1所相应的a的mac地址并记录在自己的mac表中,然后再 ...

  9. 1.1 Introduction中 Distribution官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Distribution 分布式(Distribution) The partiti ...

  10. menuconfig_kconfig

    这一节的主要内容: Menuconfig的操作 Kconfig和.config文件 Linux内核配置裁剪实验 linux编译器通过.config文件确认哪些代码编译进内核,哪些被裁减掉 menuco ...