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

from:http://blog.csdn.net/hpccn/article/details/7591662
先看效果



主要是写一个 color selector

在res/建一个文件夹取名color


res/color/color_radiobutton.xml

[html]  view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
  3.   
  4.   
  5.     <item android:state_checked="true" android:color="@color/color_text_selected"/>  
  6.     <!-- not selected -->  
  7.     <item android:color="@color/color_text_normal"/>  
  8.   
  9.   
  10. </selector>  



程序中就可以直接使用了


[html]  view plain copy
  1. //layout/main.xml  
  2. <?xml version="1.0" encoding="utf-8"?>  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     android:orientation="vertical" >  
  7.     <RadioGroup  
  8.         android:id="@+id/radiogroup_personal_condition"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:orientation="horizontal" >  
  12.         <RadioButton  
  13.             android:id="@+id/radiobutton_1"  
  14.             android:layout_width="wrap_content"  
  15.             android:layout_height="wrap_content"  
  16.             android:background="@drawable/selector_radio"  
  17.             android:button="@null"  
  18.             android:checked="true"  
  19.              android:gravity="center"  
  20.              android:text="目录"  
  21.             android:textColor="@color/color_radiobutton"  
  22.             android:textSize="@dimen/font_size"  
  23.             android:textStyle="bold" />  
  24.         <RadioButton  
  25.             android:id="@+id/radiobutton_2"  
  26.             android:layout_width="wrap_content"  
  27.             android:layout_height="wrap_content"  
  28.             android:background="@drawable/selector_radio"  
  29.             android:button="@null"  
  30.              android:gravity="center"  
  31.              android:text="书签"  
  32.             android:textColor="@color/color_radiobutton"  
  33.             android:textSize="@dimen/font_size"  
  34.             android:textStyle="bold" />  
  35.     </RadioGroup>  
  36. </LinearLayout>  


转载于:https://www.cnblogs.com/zsw-1993/archive/2012/11/05/4880675.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值