Customize the image and size of the checkbox in android

Source: Internet
Author: User

1. Create the file checkbox_selector.xml in drawable:

<? Xml version = "1.0" encoding = "UTF-8"?> <Selector xmlns: android = "http://schemas.android.com/apk/res/android"> <item android: state_checked = "true" android: drawable = "@ drawable/checkbox_ OK"/> <! -- Set the selected image --> <item android: state_checked = "false" android: drawable = "@ drawable/checkbox_empty"/> <! -- Set the unselected image --> </selector>

2. Create styles. xml in values:

<?xml version="1.0" encoding="utf-8"?><resources>  <style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox">   <item name="android:button">@drawable/checkbox_selector</item>   <item name="android:paddingLeft">25.0dip</item>   <item name="android:maxHeight">10.0dip</item>  </style></resources>

3. Add attributes to your CheckBox:

<CheckBox        android:id="@+id/check"        android:layout_width="20dp"        android:layout_height="20dp"        android:layout_marginLeft="5dp"        style="@style/MyCheckBox"          />

Related Article

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.