android⾃定义radiobutton样式⽂字颜⾊随选中状态⽽改变
android radiogroup主要是写⼀个 color selector
在res/建⼀个⽂件夹取名color
res/color/l
1<selector xmlns:android="schemas.android/apk/res/android">
2<item android:state_checked="true" android:color="@color/color_text_selected"/>
3<!-- not selected -->
4<item android:color="@color/color_text_normal"/>
5</selector>
程序使⽤:
1 //l
2<?xml version="1.0" encoding="utf-8"?>
3<LinearLayout xmlns:android="schemas.android/apk/res/android"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 android:orientation="vertical">
7<RadioGroup
8android:id="@+id/radiogroup_personal_condition"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:orientation="horizontal">
12<RadioButton
13android: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
25android: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>
附录,点击radio改变radio图⽚
1<?xml version="1.0" encoding="utf-8"?>
2<selector xmlns:android="schemas.android/apk/res/android">
3<item android:state_checked="true" android:drawable="@drawable/ic_radio_checkon"/> 4<!-- not selected -->
5<item android:drawable="@drawable/ic_radio_checkoff"/>
6
7</selector>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论