zoukankan      html  css  js  c++  java
  • RadioGroup 的 RadioButton 选择改变字体颜色和背景颜色

    RadioGroup

    [html] view plaincopy在CODE上查看代码片派生到我的代码片
     
    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 plaincopy在CODE上查看代码片派生到我的代码片
     
    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 plaincopy在CODE上查看代码片派生到我的代码片
     
    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 plaincopy在CODE上查看代码片派生到我的代码片
     
    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 plaincopy在CODE上查看代码片派生到我的代码片
     
      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>
  • 相关阅读:
    centos 研究
    python学习6 web开发
    python学习5 常用三方模块
    python学习4 常用内置模块
    python学习 3笔记
    SQLite
    mysql
    python学习 2数学公式
    python学习 1基础
    shell example02
  • 原文地址:https://www.cnblogs.com/daishuguang/p/4025530.html
Copyright © 2011-2022 走看看