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

    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();
                }
            });
  • 相关阅读:
    nethogs命令执行报异常的解决方法
    性能监控
    Linux图形化监控网络流量:speedometer查看流量
    JMeter监控Slave机器是否执行
    安全测试robots
    在ASP.NET MVC4中实现同页面增删改查,无弹出框02,增删改查界面设计
    在ASP.NET MVC4中实现同页面增删改查,无弹出框01,Repository的搭建
    报错:非介入式客户端验证规则中的验证类型名称必须唯一。下列验证类型出现重复
    ObjectStateManager 中已存在具有同一键的对象。ObjectStateManager 无法跟踪具有相同键的多个对象
    在ASP.NET MVC中使用Knockout实践09,自定义绑定
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/6034290.html
Copyright © 2011-2022 走看看