android 自定义 radiobutton 文字颜色随选中状态而改变
来源:互联网 发布:it实验室 编辑:程序博客网 时间:2024/05/22 00:36
http://blog.csdn.net/kevinmeng_ini58/article/details/8809681
http://blog.csdn.net/kevinmeng_ini58/article/details/8809681http://blog.csdn.net/kevinmeng_ini58/article/details/8809681
android 自定义 radiobutton 文字颜色随选中状态而改变
分类:
版权声明:本文为博主原创文章,未经博主允许不得转载。
第一部分:转自http://blog.csdn.net/hpccn/article/details/7591662?reload
先看效果
主要是写一个 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>
第二部分:原创
如果使用代码生成第一部分效果该如何实现呢?
第一步,同样需要res/color/color_radiobutton.xml
第二步:
- //该方法加载不同状态的颜色组合
- ColorStateList csl = getResources().getColorStateList(R.color.color_sub_categories_radio_button);
- radioButton.setTextColor(csl);
最后附上所有可能出现的状态:
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android" >
- <item
- android:color="hex_color"
- android:state_pressed=["true" | "false"]
- android:state_focused=["true" | "false"]
- android:state_selected=["true" | "false"]
- android:state_active=["true" | "false"]
- android:state_checkable=["true" | "false"]
- android:state_checked=["true" | "false"]
- android:state_enabled=["true" | "false"]
- android:state_window_focused=["true" | "false"] />
- </selector>
0 0
- android 自定义 radiobutton 文字颜色随选中状态而改变
- android 自定义 radiobutton 文字颜色随选中状态而改变
- android 自定义 radiobutton 文字颜色随选中状态而改变
- android 自定义 radiobutton 文字颜色随选中状态而改变
- android 自定义 radiobutton 文字颜色随选中状态而改变
- android 自定义 radiobutton 文字颜色随选中状态而改变
- android 自定义 radiobutton 文字颜色随选中状态而改变
- android 自定义 radiobutton 文字颜色随选中状态而改变
- Android Radiobutton 文字颜色随选中状态而改变
- Android的RadioButton随着选中状态的改变字体颜色也改变
- radio选中状态对应文字改变颜色
- radiobutton 文字颜色改变
- android listview 选中部分 文字颜色改变
- android radiobutton选中字体颜色改变的方法
- android radioButton 选中后改变字体颜色样式
- 文字根据状态改变颜色 android:textColor
- 字体颜色随选中状态改变
- RadioGroup+RadioButton嵌套其他布局实现多行单选布局、自定义RadioButton选中和非选中样式、文字颜色
- UI设计实验一
- 实习报告
- sql server —表的管理
- shell脚本
- 家庭仿真机器人之任务场景截取
- android 自定义 radiobutton 文字颜色随选中状态而改变
- 负载均衡技术与分类
- Groovy入门教程
- 深入理解HashMap(及hash函数的真正巧妙之处)
- 在组合与继承之间的选择
- autorelease 的封装
- LeetCode 237. Delete Node in a Linked List
- 大事故发生
- Vmware vSphere 出现 unable to connect to the mks问题的解决办法