Android custom RadioButton style text color changes with selected state

Source: Internet
Author: User

The main is to write a color selector

Build a folder in Res/name color

Res/color/color_radiobutton.xml

1 <selectorxmlns:android= "Http://schemas.android.com/apk/res/android">  2   <Itemandroid:state_checked= "true"Android:color= "@color/color_text_selected"/>  3     <!--Not selected -  4     <ItemAndroid:color= "@color/color_text_normal"/>  5   </selector>  

Program use:

1 //layout/main.xml2 <?XML version= "1.0" encoding= "Utf-8"?>  3 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"  4 Android:layout_width= "Fill_parent"  5 Android:layout_height= "Fill_parent"  6 android:orientation= "vertical" >  7     <Radiogroup8         Android:id= "@+id/radiogroup_personal_condition"  9 Android:layout_width= "Wrap_content"  Ten Android:layout_height= "Wrap_content"   One android:orientation= "Horizontal" >   A         <RadioButton -             Android:id= "@+id/radiobutton_1"   - Android:layout_width= "Wrap_content"   the Android:layout_height= "Wrap_content"   - Android:background= "@drawable/selector_radio"   - Android:button= "@null"   - android:checked= "true"   + android:gravity= "Center"   - Android:text= "Directory"   + Android:textcolor= "@color/color_radiobutton"   A android:textsize= "@dimen/font_size"   at Android:textstyle= "Bold" />   -         <RadioButton -             Android:id= "@+id/radiobutton_2"   - Android:layout_width= "Wrap_content"   - Android:layout_height= "Wrap_content"   - Android:background= "@drawable/selector_radio"   in Android:button= "@null"   - android:gravity= "Center"   to Android:text= "Bookmark"   + Android:textcolor= "@color/color_radiobutton"   - android:textsize= "@dimen/font_size"   the Android:textstyle= "Bold" />   *     </Radiogroup>   $ </LinearLayout> 

Appendix, click Radio To change Radio picture

1 <?XML version= "1.0" encoding= "Utf-8"?>  2 <selectorxmlns:android= "Http://schemas.android.com/apk/res/android">  3     <Itemandroid:state_checked= "true"android:drawable= "@drawable/ic_radio_checkon"/>  4     <!--Not selected -  5     <Itemandroid:drawable= "@drawable/ic_radio_checkoff"/>  6   7 </selector>  

Android custom RadioButton style text color changes with selected state

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.