Radiobutton of radiogroup selects to change the font color and background color.

Source: Internet
Author: User

Radiogroup

[HTML]View plaincopy
  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. <Radiobutton
  13. Android: Id = "@ + ID/client_radio_label"
  14. Android: layout_width = "0dp"
  15. Android: layout_height = "match_parent"
  16. Android: layout_weight = "1"
  17. Android: button = "@ color/transparent"
  18. Android: gravity = "center"
  19. Android: text = "client"
  20. Android: textcolor = "@ color/color_radiobutton"
  21. Android: Background = "@ drawable/radio_group_selector"
  22. />
  23. <Radiobutton
  24. Android: Id = "@ + ID/firm_radio_label"
  25. Android: layout_width = "0dp"
  26. Android: layout_height = "match_parent"
  27. Android: layout_weight = "1"
  28. Android: button = "@ color/transparent"
  29. Android: gravity = "center"
  30. Android: text = "firm"
  31. Android: checked = "true"
  32. Android: textcolor = "@ color/color_radiobutton"
  33. Android: Background = "@ drawable/radio_group_selector"/>
  34. </Radiogroup>


 

Radiobutton font color change color_radiobutton.xml

[HTML]View plaincopy
  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 background color change radio_group_selector.xml

[HTML]View plaincopy
  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
  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
    1. Clientradiogroup = (radiogroup) findviewbyid (R. Id. client_charge_radiogroup );
    2. Clientradiogroup. setoncheckedchangelistener (New oncheckedchangelistener (){
    3. @ Override
    4. Public void oncheckedchanged (radiogroup group, int checkedid ){
    5. Int radiobuttonid = group. getcheckedradiobuttonid ();
    6. Radiobutton RB = (radiobutton) findviewbyid (radiobuttonid );
    7. String radiobuttonlabel = RB. gettext (). tostring ();
    8. }
    9. });

 

Http://blog.csdn.net/zzf112/article/details/20467957

 

--------------------->

Android: Background = "@ drawable/drawlist" ---------> colorlist cannot be used.

Radiogroup -------> radiobutton must have an id. Otherwise, both are selected.

 

<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 = "seating arrangements" 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 = "menu editing" Android: textcolor = "# ffffff"/> </radiogroup>

 

Radiobutton of radiogroup selects to change the 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.