android自定义控件之radioButton
来源:互联网 发布:中国网络成语大赛 编辑:程序博客网 时间:2024/05/07 11:10
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">想要实现一个随着选中事件改变radiobutton 中字体颜色和背景颜色的功能。</span>
在src下新建文件夹color,新建radio_textcolor.xml文件。
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:color="@color/selected"/> <!-- not selected --> <item android:color="@color/unselected"/></selector>
其中selected 和unselected在value>colors.xml中定义:
<?xml version="1.0" encoding="utf-8"?><resources> <color name="selected">#ffffff</color> <color name="unselected">#000000</color> <color name="background">#EAEAEA</color></resources>
接下来需要自定义背景图片,和字体颜色差不多写到一个xml中。这里在drawable>文件夹下新建radio_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/unselected" /> <item android:state_checked="true" android:drawable="@drawable/selected" /> </selector>
其中selected.png 和unselected.png自己选择的图片。
然后在values>styles.xml中创建我们的style;
<style name="myradiostyle"> <item name="android:background">@drawable/radio_background</item> <item name="android:textColor">@color/radio_textcolor</item></style>
到此基本完成了,在布局文件中直接引用了。
<RadioGroup android:id="@+id/radiogroup_personal_condition" android:layout_width="wrap_content" android:layout_height="40dip" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:layout_marginTop="30dip" android:orientation="horizontal" > <RadioButton android:id="@+id/radiobutton_1" style="@style/myradiostyle" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:button="@null" android:checked="true" android:gravity="center" android:text="排名" android:textStyle="bold" /> <RadioButton android:id="@+id/radiobutton_2" style="@style/myradiostyle" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:button="@null" android:gravity="center" android:text="历史" android:textStyle="bold" /> <RadioButton android:id="@+id/radiobutton_3" style="@style/myradiostyle" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="1" android:button="@null" android:gravity="center" android:text="实时" android:textStyle="bold" /> </RadioGroup>
运行看看效果!ok!
0 0
- android自定义控件之radioButton
- Android 控件开发之 RadioButton
- android控件之radiobutton checkbox
- android 控件之RadioGroup&RadioButton
- Android 控件开发之 RadioButton
- Android控件之RadioGroup、RadioButton
- Android控件之CheckBox、RadioButton
- Android之RadioButton控件使用
- 自定义控件RadioButton EditText
- Android控件之CheckBox、RadioButton探究
- Android控件系列之RadioButton&RadioGroup
- Android基础控件之单选框(RadioButton)
- Android UI控件之RadioGroup、RadioButton
- Android控件系列之RadioButton&RadioGroup
- Android控件系列之RadioButton&RadioGroup
- Android控件系列之RadioButton&RadioGroup
- Android控件系列之RadioButton&RadioGroup
- Android控件系列之RadioButton&RadioGroup
- 【AllJoyn框架-01】连接PC与Arduino Due开发板
- ViewStub的应用
- 重构机房收费系统—浅谈三层
- Peterson和多线程版本
- Android开源框架ImageLoader的完美例子
- android自定义控件之radioButton
- android 自定义ScrollView实现背景图片伸缩的实现代码及思路
- CSS控制DIV绝对定位、相对定位的技巧
- Android获取系统cpu信息,内存,版本,电量相关信息
- 数据库的增删改查及表的建立和删除
- RabbitMQ 安装配置与管理
- LINQ to SQL和Entity Framework对比
- GNU ARM 汇编指令(注意是GNU,区别与armasm)
- CXF+Web Service入门实例展示