[Android instance] changing the style of a checkbox

Source: Internet
Author: User

First, add the following custom style to the Styles.xml:

    1. <style name= "MyCheckBox" parent= "@android: Style/widget.compoundbutton.checkbox" >
    2. <item name= "Android:button" > @drawable/my_checkbox</item>
    3. </style>
Copy Code

The contents of the My_checkbox.xml are:

  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= "@drawable/checkbox_pressed"/>
  4. <item android:state_checked= "false" android:drawable= "@drawable/checkbox"/>
  5. <item android:drawable= "@drawable/checkbox"/>
  6. </selector>
Copy Code

Code snippets that use custom styles:

  1. <checkbox
  2. Android:id= "@+id/checked"
  3. Android:layout_alignparentright= "true"
  4. android:layout_marginright= "10dip"
  5. Android:layout_centervertical= "true"
  6. Android:layout_width= "40dip"
  7. android:layout_height= "Wrap_content"
  8. Android:checked= "false"
  9. style= "@style/mycheckbox"
  10. />
Copy Code

Add two photos checkbox_pressed.png, checkbox.png

http://www.eoeandroid.com/forum.php?mod=viewthread&tid=148630

[Android instance] changing the style of a checkbox

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.