RadioGroup 的 RadioButton 选择改变字体颜色和背景颜色
选择 改变 颜色 字体 背景 RadioButton RadioGroup
2023-09-11 14:16:42 时间
RadioGroup
- <RadioGroup
- android:id="@+id/client_charge_radiogroup"
- android:layout_width="200dp"
- android:layout_height="40dp"
- android:layout_marginLeft="5dp"
- android:layout_alignParentRight="true"
- android:fadingEdge="none"
- android:gravity="center_vertical"
- android:layout_centerVertical="true"
- android:orientation="horizontal"
- >
- <RadioButton
- android:id="@+id/client_radio_label"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:button="@color/transparent"
- android:gravity="center"
- android:text="Client"
- android:textColor="@color/color_radiobutton"
- android:background="@drawable/radio_group_selector"
- />
- <RadioButton
- android:id="@+id/firm_radio_label"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:button="@color/transparent"
- android:gravity="center"
- android:text="Firm"
- android:checked="true"
- android:textColor="@color/color_radiobutton"
- android:background="@drawable/radio_group_selector"/>
- </RadioGroup>
radiobutton字体颜色改变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:state_checked="false" android:color="@color/color_text_normal"/>
- </selector>
radiobutton背景颜色改变radio_group_selector.xml
- <?xml version="1.0" encoding="utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android" >
- <item android:state_checked="true" android:drawable="@color/color_bg_selected" ></item>
- <item android:state_checked="false" android:drawable="@color/color_bg_normal"></item>
- </selector>
color.xml
- <color name="transparent">#000000</color>
- <color name="color_bg_selected">#e0301e</color>
- <color name="color_bg_normal">#e7e7e8</color>
- <color name="color_text_selected">#ffffff</color>
- <color name="color_text_normal">#000000</color>
Activity
- clientRadioGroup = (RadioGroup) findViewById(R.id.client_charge_radiogroup);
- clientRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(RadioGroup group, int checkedId) {
- int radioButtonId = group.getCheckedRadioButtonId();
- RadioButton rb = (RadioButton)findViewById(radioButtonId);
- String radioButtonLabel = rb.getText().toString();
- }
- });
http://blog.csdn.net/zzf112/article/details/20467957
--------------------->
android:background="@drawable/drawlist"--------->不能用colorlist
radiogroup------->radiobutton必须要有id否则会两个都选中
<RadioGroup android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal" > <RadioButton android:id="@+id/radio0" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/zuowei" android:button="@null" android:checked="true" android:gravity="center" android:text="座位安排" android:textColor="#ffffff" /> <RadioButton android:id="@+id/radio1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/zuowei" android:button="@null" android:gravity="center" android:text="菜单编辑" android:textColor="#ffffff" /> </RadioGroup>
相关文章
- 欧盟指控微软未遵守承诺提供浏览器选择
- 【经典算法】直接选择排序
- C# 获取选择文件信息
- Attachment assignment block里选择的文件是如何传到Netweaver服务器的
- Attachment assignment block里选择的文件是如何传到Netweaver服务器的
- “全球+”浪潮下,企业出海选择合适的“技术船舶”成关键
- 我为什么选择投身网络游戏事业
- VB编程:SelectCase多分支选择结构实例测试生肖运势-13
- cocos2d-html5游戏图片资源选择
- 一次正确选择,改变一生命运!
- 059:vue+openlayers点击选择feature,并设置特定的颜色(示例代码)
- 切换镜像源 r 选择镜像 调用chooseCRANmirror函数:
- 测试小故事81:焦虑中选择
- HttpServlet中,用来处理POST请求的方法是(选择1项)
- 最终,为什么选择go-kit
- 深度好文丨现在转行程序员还是一个好选择吗?