展会信息港展会大全

android 自定义 radiobutton 文字颜色随选中状态而改变
来源:互联网   发布日期:2015-12-04 16:28:27   浏览:2144次  

导读:android 自定义 radiobutton 文字颜色随选中状态而改变先看效果主要是写一个 color selector在res/建一个文件夹取名colorres/color/color_radiobutton.xml?xml version=1.0 encoding=utf-8?select......

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

先看效果

主要是写一个 color selector

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

res/color/color_radiobutton.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/color_text_selected"/>

<!-- not selected -->

<item android:color="@color/color_text_normal"/>

</selector>

程序中就可以直接使用了

layout/main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<RadioGroup

android:id="@+id/radiogroup_personal_condition"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal" >

<RadioButton

android:id="@+id/radiobutton_1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/selector_radio"

android:button="@null"

android:checked="true"

android:gravity="center"

android:text="目录"

android:textColor="@color/color_radiobutton"

android:textSize="@dimen/font_size"

android:textStyle="bold" />

<RadioButton

android:id="@+id/radiobutton_2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/selector_radio"

android:button="@null"

android:gravity="center"

android:text="书签"

android:textColor="@color/color_radiobutton"

android:textSize="@dimen/font_size"

android:textStyle="bold" />

</RadioGroup>

</LinearLayout>

赞助本站

人工智能实验室

相关热词: 文字颜色 radiobutton

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港