Android 自定义RadioButton样式
上面这种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样式的更多相关文章
- 转:android 自定义RadioButton样式
http://gundumw100.iteye.com/blog/1146527 上面这种3选1的效果如何做呢?用代码写? 其实有更简单的办法,忘了RadioButton有什么特性了吗? 我就用Ra ...
- android自定义radiobutton样式文字颜色随选中状态而改变
主要是写一个 color selector 在res/建一个文件夹取名color res/color/color_radiobutton.xml <selector xmlns:android= ...
- Android 自定义RadioButton的样式
Android 自定义RadioButton的样式 我们知道Android控件里的button,listview可以用xml的样式自定义成自己希望的漂亮样式. 最近用到RadioButton,利用xm ...
- Android 自定义RadioButton实现
由于使用小米系统MIUI运行是RadioButton样式跟google Android API自定义的不一样,则我们可以定义任何想要的东东.没有做不到,只有想不到 Android 自定义RadioBu ...
- wpf radiobuttong 去前面的圆点, 自定义radiobutton样式
自定义radiobutton样式代码: <windows.Resources> <LinearGradientBrush x:Key="CheckRadioFillNorm ...
- Android: 自定义Tab样式,一种简单的方式。
之前看到过论坛里已经有人发过自定义Tab样式的帖子,感觉有些复杂了,这里分享个简单的方法. 1.制作4个9patch的tab样式,可参考android默认的资源 tab_unselected.9.pn ...
- 自定义RadioButton样式
一,在RadioButton标签上使用 android:button="@drawable/pay_radio_selector" 可以修改按钮的样式 二,在RadioButton ...
- Android 自定义title样式
requestWindowFeature(featrueId),它的功能是启用窗体的扩展特性.参数是Window类中定义的常量.一.枚举常量1.DEFAULT_FEATURES:系统默认状态,一般不需 ...
- Android自定义ProgressBar样式
我们使用的进度条多种多样,下面有几种自定义的进度条的样式,下面介绍几个. 进度条的有基本的四种样式: 默认风格的进度条: android:progressBarStyle 水平长型进度条: andro ...
随机推荐
- worktools-mmx 添加编译模块
1,添加模块到mmx.py文件 1>vim /home/zhangshuli/git/vanzo_team/xulei/mmx.py 2>按照格式"Gallery2": ...
- eclipse- MAT安装及使用
1.安装eclipse mat插件 1)查看当前eclipse版本 进入eclipse目录:右击eclipse图标,看到安装目录/home/zhangshuli/adt-bundle-linux-x8 ...
- POJ 1082 Calendar Game
Adam and Eve enter this year's ACM International Collegiate Programming Contest. Last night, they pl ...
- Linux的用户和组管理
1.用户和组 一个用户必须有一个主组 一个用户可以同时属于多个组 一个组可以拥有多个用户 用户信息存在: /etc/passwd 组信息存在:/etc/group 密码信息存在: /etc/shado ...
- Django快速搭建博客
准备工作: 1.Python 2.Django 3.Git 安装Python: 官网下载 安装Django: #安装最新版本的Django $ pip install django #或者指定安装版本 ...
- spring基础内容
关注和收藏在这里 深入理解Spring框架的作用 纵览Spring , 读者会发现Spring 可以做非常多的事情. 但归根结底, 支撑Spring的仅仅是少许的基本理念, 所有的理念都可以追 ...
- MFC窗口显隐
使用SetLayeredWindowAttributes可以方便的制作透明窗体,此函数在w2k以上才支持,而且如果希望直接使用的话,可能需要下载最新的SDK.不过此函数在w2k的user32.dll里 ...
- css基础属性
color:设置文本颜色:属性值:1.表示颜色的英文单词,例如:red.blue.green.pink.purple.cyan等:2.十六进制表示法:#ff0000: 0.1.2...9.a.b.c. ...
- Django的命令
安装django : pip install django 创建django项目 :django-admin startproject projectname 启动django项 ...
- Docker---(7)Docker安装启动RabbitMQ
原文:Docker---(7)Docker安装启动RabbitMQ 版权声明:欢迎转载,请标明出处,如有问题,欢迎指正!谢谢!微信:w1186355422 https://blog.csdn.net/ ...