码迷,mamicode.com
首页 > 其他好文 > 详细

RadioGroup 的 RadioButton 选择改变字体颜色和背景颜色

时间:2014-10-15 04:13:59      阅读:467      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   http   color   io   os   ar   java   

RadioGroup

[html] view plaincopybubuko.com,布布扣bubuko.com,布布扣
 
  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] view plaincopybubuko.com,布布扣bubuko.com,布布扣
 
  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] view plaincopybubuko.com,布布扣bubuko.com,布布扣
 
  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] view plaincopybubuko.com,布布扣bubuko.com,布布扣
 
  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] view plaincopybubuko.com,布布扣bubuko.com,布布扣
 
    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.         });  

 

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>

 

RadioGroup 的 RadioButton 选择改变字体颜色和背景颜色

标签:android   style   blog   http   color   io   os   ar   java   

原文地址:http://www.cnblogs.com/daishuguang/p/4025530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!