RadioButton自定义多选一效果
2016-02-18 13:42
85 查看
RadioButton自定义多选一效果
首先,准备一个selector文件,作为RadioButton的背景
这里要注意他们的状态:state-checked1. <?xml version="1.0" encoding="utf-8"?> 2. <selector xmlns:android="http://schemas.android.com/apk/res/android"> 3. <item 4. android:state_checked="false" 5. android:drawable="@drawable/tabswitcher_long" /> 6. <item 7. android:state_checked="true" 8. android:drawable="@drawable/tabswitcher_short" /> 9. </selector>
在布局中引用该selector
重要属性:android:checkedButton="@+id/rb_transition"
android:checkedButton="@+id/rb_transition":该属性的作用是,设置初始化状态下,指定默认选中的按钮的id。这里要特别的用+id,这是因为xml文件编译是有顺序的,要使用比自己后编译的id要使用“+id”;或者是在指定的RadioButton下设置android:checked="true"。
android:button="@null":该属性的作用可以去掉系统自带的背景图(就是一个空心圆和一个实心圆);使用后,再调用背景才能生效,否则会被默认图标遮盖
<RadioGroup android:gravity="center" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:checkedButton="@+id/rb_0" > <RadioButton android:id="@+id/rb_0" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="RadioButton1" 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/rb_1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="RadioButton2" 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/rb_2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="RadioButton3" android:textSize="17.0sp" android:textColor="@android:color/black" android:gravity="center" android:layout_weight="1" android:button="@null" android:background="@drawable/radio" /> </RadioGroup>
相关文章推荐
- Flex4 DataGrid中嵌入RadioButton实现思路及代码
- c# 如何将RadioButton与DataTable数据进行绑定
- C#实现自定义双击事件
- WinForm实现自定义右下角提示效果的方法
- Android控件之CheckBox、RadioButton用法实例分析
- MFC自定义消息的实现方法
- C#实现ProperTyGrid自定义属性的方法
- php自定义错误处理用法实例
- ThinkPHP中自定义目录结构的设置方法
- C#自定义事件监听实现方法
- C#自定义事件及用法实例
- C#自定义签名章实现方法
- C#中使用IFormattable实现自定义格式化字符串输出示例
- javascript 自定义常用方法第1/2页
- 谈谈JavaScript自定义回调函数
- 自定义jQuery插件方式实现强制对象重绘的方法
- jQuery实现自定义checkbox和radio样式
- Jquery Mobile 自定义按钮图标
- jquery自定义插件开发之window的实现过程
- jQuery实现自定义事件的方法