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>
  • 相关阅读:
    使用IDEA工具配置和运行vue项目(详细其中的坑)
    VSCode打开已有vuejs项目
    vue中遇到的问题:Error: Cannot find module 'chalk'
    Qt源码分析之信号和槽机制(QMetaObject是一个内部struct)
    “ping”命令的原理就是向对方主机发送UDP数据包,HTTP在每次请求结束后都会主动释放连接,因此HTTP连接是一种“短连接”
    程序员保值的4个秘密(要当语言和框架方面的专家,高难技术,业务,算法,产品意识与思维(把细节做好))
    C++ 多线程阻塞 (多线程同步)(MsgWaitForMultipleObjects)(连着消息一起控制,牛)
    兴趣与坚持:程序员从初级到中级10个秘诀(要学另一门语言,学会搜索,找到真正令你着迷的东西,不能为工资、要真正享受工作)
    Spring MVC 数据回显
    内存问题检测神器:Valgrind
  • 原文地址:https://www.cnblogs.com/daishuguang/p/4025530.html
Copyright © 2011-2022 走看看