赞
踩
<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>
- <?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 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>
然后在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>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。