Follow Android 007, get a full set of Free Android development learning materials

What is the CheckBox

CheckBox is a UI control for displaying checkboxes.

Based on the sample

1. The common check box

rendering

code

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I am the CheckBox" />
Copy the code

2. Set the size

rendering

code

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I'm a 20 point font CheckBox."
    android:textSize="20sp" />
Copy the code

3. Set the color

rendering

code

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I am the red CheckBox."
    android:textColor="#FF0000" />
Copy the code

4. Set bold

rendering

code

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I'm a bold CheckBox."
    android:textStyle="bold" />
Copy the code

5. Select the Settings

rendering

code

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="true"
    android:text="I'm the CheckBox." />
Copy the code

Basic sample complete source code

Gitee.com/cxyzy1/Chec…

Common Attributes

The property name use
android:layout_width Set the width of the control to match_parent(same as the parent control),wrap_content(automatic scaling based on the content), fixed values (such as 200dp)
android:layout_height Set the height of the control to match_parent(same as the parent control),wrap_content(automatic scaling based on the content), fixed value (such as 200dp)
android:gravity Control for internal alignment
android:background Set the background, which can be a color value (such as #FF0000) or an image
android:visibility Optional values: Visible (display), invisible(hidden, but still occupies UI space),gone(hidden, and does not occupy UI space)
android:text Setting text content
android:textSize Set the font size
android:textColor Set the color
android:textStyle Set the font style. Optional values: Normal (normal),bold(italic)
android:checked Check whether, optional values :true(check),false(unchecked)

More properties and actual effects can be experienced in the development tool.


Android development tutorial series summary

Development language learning

Kotlin language basics

UI control learning series

UI control _TextView UI control _EditText UI control _Button UI control _ImageView UI control _RadioButton UI control _CheckBox UI control _ProgressBar

Follow the headlines to get the latest articles: