Customizing the Android Style checkbox

Source: Internet
Author: User

Below is a brief introduction to how to change the background picture of a checkbox in Androdi, you can customize the style

1, first res/drawable in the definition of writing the following style of XML, named: Checkbox_style:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <selectorxmlns:android= "Http://schemas.android.com/apk/res/android">3     <Itemandroid:drawable= "@drawable/checkbox2"android:state_checked= "true"></Item>4     <Itemandroid:drawable= "@drawable/checkbox"android:state_checked= "false"></Item>5     <Itemandroid:drawable= "@drawable/checkbox"/>   6 </selector>

2. Then add the checkbox control to the layout file as follows:

1  <CheckBox2                 Android:id= "@+id/checkbox1"3 Android:layout_width= "Wrap_content"4 Android:layout_height= "Wrap_content"5 android:layout_centervertical= "true"6 Android:button= "@null"7 Android:background= "@drawable/checkbox_style" />

Where Drwable/checkbox_style is the XML name for the style file that defines the checkbox, Android:button must also be set to @null. Otherwise, the check-in style of Android comes with it. You can test to see @drawable/checkbox as checkbox unselected picture, @drawable/checkbox2 as checkbox selected picture

Customizing the Android Style 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.