Custom CheckBox component Instance _android in Android

Source: Internet
Author: User

In Android, a checkbox is a very important UI component, and in Android it shows more and more beautifully, which means that some systems For example 4.0 below, the checkbox is still not good-looking, or with the software style is not coordinated, we need to customize this component.

Customizing this component is simple, and simply adding changes to the XML file.

Preparatory work

Prepare two pictures, one is the selected picture, the other is the unselected picture. This paper takes checked.png and unchecked.png as examples.

Set Selection box

Create a new file under Drawable custom_checkbox.xml

Copy Code code as follows:

<?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/checked" ></item>
<item android:state_checked= "false" android:drawable= "@drawable/unchecked" ></item>
<item android:drawable= "@drawable/unchecked" ></item><!--the default one-->
</selector>

Apply a custom

Set the Button property value to the Custom_checkbox defined above.

Copy Code code as follows:

<checkbox
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:button= "@drawable/custom_checkbox"
/>

Custom finished, run up your program.

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.