Android radiogroup RadioButton Choose to change font color and background color

Source: Internet
Author: User

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 Font Color Change 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 Background color Change 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             publicvoidint  checkedid) {                int Radiobuttonid =  Group.getcheckedradiobuttonid ();                 = (RadioButton) Findviewbyid (Radiobuttonid);                 = Rb.gettext (). toString ();            }        );

RadioButton selection of Android radiogroup change font color and background color

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.