博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
RadioGroup 的 RadioButton 选择改变字体颜色和背景颜色
阅读量:7226 次
发布时间:2019-06-29

本文共 2496 字,大约阅读时间需要 8 分钟。

RadioGroup

[html] 
 
  1. <RadioGroup  
  2.             android:id="@+id/client_charge_radiogroup"  
  3.             android:layout_width="200dp"  
  4.             android:layout_height="40dp"  
  5.             android:layout_marginLeft="5dp"  
  6.             android:layout_alignParentRight="true"  
  7.             android:fadingEdge="none"  
  8.             android:gravity="center_vertical"  
  9.             android:layout_centerVertical="true"  
  10.             android:orientation="horizontal"   
  11.             >  
  12.           
  13.             <RadioButton  
  14.                 android:id="@+id/client_radio_label"  
  15.                 android:layout_width="0dp"  
  16.                 android:layout_height="match_parent"  
  17.                 android:layout_weight="1"  
  18.                 android:button="@color/transparent"  
  19.                 android:gravity="center"  
  20.                 android:text="Client"  
  21.                 android:textColor="@color/color_radiobutton"  
  22.                 android:background="@drawable/radio_group_selector"   
  23.                 />  
  24.           
  25.             <RadioButton  
  26.                 android:id="@+id/firm_radio_label"  
  27.                 android:layout_width="0dp"  
  28.                 android:layout_height="match_parent"  
  29.                 android:layout_weight="1"  
  30.                 android:button="@color/transparent"  
  31.                 android:gravity="center"  
  32.                 android:text="Firm"   
  33.                 android:checked="true"  
  34.                 android:textColor="@color/color_radiobutton"  
  35.                 android:background="@drawable/radio_group_selector"/>  
  36.         </RadioGroup>  

 

radiobutton字体颜色改变color_radiobutton.xml

[html] 
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <item android:state_checked="true" android:color="@color/color_text_selected"/>    
  4.     <!-- not selected -->    
  5.     <item android:state_checked="false" android:color="@color/color_text_normal"/>    
  6. </selector>  

 

radiobutton背景颜色改变radio_group_selector.xml

[html] 
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >  
  3.     <item android:state_checked="true" android:drawable="@color/color_bg_selected" ></item>  
  4.     <item android:state_checked="false" android:drawable="@color/color_bg_normal"></item>  
  5. </selector>  

color.xml

[html] 
 
  1. <color name="transparent">#000000</color>  
  2.     <color name="color_bg_selected">#e0301e</color>  
  3.     <color name="color_bg_normal">#e7e7e8</color>  
  4.     <color name="color_text_selected">#ffffff</color>  
  5.     <color name="color_text_normal">#000000</color>  

 

Activity

[java] 
 
    1. clientRadioGroup = (RadioGroup) findViewById(R.id.client_charge_radiogroup);  
    2.         clientRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {  
    3.               
    4.             @Override  
    5.             public void onCheckedChanged(RadioGroup group, int checkedId) {  
    6.                 int radioButtonId = group.getCheckedRadioButtonId();  
    7.                 RadioButton rb = (RadioButton)findViewById(radioButtonId);  
    8.                 String radioButtonLabel = rb.getText().toString();  
    9.             }  
    10.         });  

 

 

--------------------->

android:background="@drawable/drawlist"--------->不能用colorlist

radiogroup------->radiobutton必须要有id否则会两个都选中

 

 

转载地址:http://wudfm.baihongyu.com/

你可能感兴趣的文章
Linux --DHCP服务器配置;DHCP服务器中继
查看>>
IE版本多的可爱_已迁移
查看>>
eclipse查看jar包中class的中文注释乱码问题的解决
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
mariadb安装
查看>>
vue+vuex+axios+echarts画一个动态更新的中国地图
查看>>
5.8 volumetric post-processing--game programming gems5 笔记
查看>>
8086的地址空间
查看>>
Android开发动画效果被遮掉的解决方法
查看>>
Apache2.2.17源码编译安装以及配置虚拟主机
查看>>
2017年开发语言排名
查看>>
读二进制表的显示 Binary Watch
查看>>
我的友情链接
查看>>
linux基础:10、基础命令(4)
查看>>
linux中强大的screen命令
查看>>
放开那个程序员
查看>>
构建高性能数据库缓存之Redis(一)
查看>>
测试驱动开发
查看>>
解决MySQL不允许从远程访问
查看>>