1e41f4b71Sopenharmony_ci# Checkbox
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci**Checkbox** is a component that is used to enable or disable an option.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  Since API version 11, the default style of the **Checkbox** component is changed from rounded square to circle.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci>  This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Child Components
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciNot supported
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## APIs
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciCheckbox(options?: CheckboxOptions)
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciCreates a check box.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Parameters** 
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name | Type                                       | Mandatory | Description              |
30e41f4b71Sopenharmony_ci| ------- | ------------------------------------------- | ---- | ------------------ |
31e41f4b71Sopenharmony_ci| options | [CheckboxOptions](#checkboxoptions) | No  | Check box parameters. |
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci## CheckboxOptions
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
36e41f4b71Sopenharmony_ci| --------| --------| ------ | -------- |
37e41f4b71Sopenharmony_ci| name    | string | No | Name of the check box.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
38e41f4b71Sopenharmony_ci| group   | string | No | Group name of the check box (that is, the name of the check box group to which the check box belongs).<br>**NOTE**<br>For the settings to take effect, this parameter must be used with the [CheckboxGroup](ts-basic-components-checkboxgroup.md) component.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
39e41f4b71Sopenharmony_ci| indicatorBuilder<sup>12+</sup> | [CustomBuilder](ts-types.md#custombuilder8) | No | Custom component to indicate that the check box is selected. This custom component is center aligned with the check box. When **indicatorBuilder** is set to **undefined** or **null**, it defaults to the state where it is not set.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci## Attributes
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci### select
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ciselect(value: boolean)
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ciSets whether the check box is selected.
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ciSince API version 10, this attribute supports two-way binding through [$$](../../../quick-start/arkts-two-way-sync.md).
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci**Parameters** 
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                              |
62e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------------- |
63e41f4b71Sopenharmony_ci| value  | boolean | Yes  | Whether the check box is selected.<br>Default value: **false** |
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci### selectedColor
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ciselectedColor(value: ResourceColor)
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ciSets the color of the check box when it is selected.
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci**Parameters** 
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci| Name | Type                                      | Mandatory | Description                                                        |
80e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------------------------------------------------ |
81e41f4b71Sopenharmony_ci| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Color of the check box when it is selected.<br>Default value: **$r('sys.color.ohos_id_color_text_primary_activated')**<br>An invalid value is handled as the default value. |
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci### unselectedColor<sup>10+</sup>
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ciunselectedColor(value: ResourceColor)
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ciSets the border color of the check box when it is not selected.
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**Parameters** 
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci| Name | Type                                      | Mandatory | Description                      |
96e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | -------------------------- |
97e41f4b71Sopenharmony_ci| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Border color of the check box when it is not selected.<br>Default value: **'#33ffffff'** |
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci### mark<sup>10+</sup>
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_cimark(value: MarkStyle)
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ciSets the mark style of the check box.
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci**Parameters** 
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci| Name | Type                             | Mandatory | Description                |
112e41f4b71Sopenharmony_ci| ------ | --------------------------------- | ---- | -------------------- |
113e41f4b71Sopenharmony_ci| value  | [MarkStyle](ts-types.md#markstyle10) | Yes  | Mark style of the check box. Since API version 12, if **indicatorBuilder** is set, the content configured in **indicatorBuilder** will be displayed accordingly.|
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci### shape<sup>11+</sup>
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_cishape(value: CheckBoxShape)
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ciSets the shape of the check box.
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 11.
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**Parameters** 
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory | Description                                                        |
130e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ------------------------------------------------------------ |
131e41f4b71Sopenharmony_ci| value  | [CheckBoxShape](#checkboxshape11) | Yes  | Shape of the check box.<br>Default value: **CheckBoxShape.CIRCLE** |
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci### contentModifier<sup>12+</sup>
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_cicontentModifier(modifier: ContentModifier\<CheckBoxConfiguration>)
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ciCreates a content modifier.
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci**Parameters**
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory | Description                                            |
146e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ------------------------------------------------ |
147e41f4b71Sopenharmony_ci| modifier  | [ContentModifier\<CheckBoxConfiguration>](#checkboxconfiguration12) | Yes  | Content modifier to apply to the check box.<br>**modifier**: content modifier. You need a custom class to implement the **ContentModifier** API. |
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci## Events
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ciIn addition to the [universal events](ts-universal-events-click.md), the following attributes are supported.
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci### onChange
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_cionChange(callback: (value: boolean) => void)
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ciInvoked when the selection status of the check box changes.
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci**Parameters** 
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                                             |
168e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------- |
169e41f4b71Sopenharmony_ci| value  | boolean | Yes  | Whether the check box is selected. The value **true** means that the check box is selected, and **false** means the opposite. |
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci## CheckBoxShape<sup>11+</sup>
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci| Name          | Value  | Description    |
176e41f4b71Sopenharmony_ci| -------------- | ---- | -------- |
177e41f4b71Sopenharmony_ci| CIRCLE         | 0    | Circle.    |
178e41f4b71Sopenharmony_ci| ROUNDED_SQUARE | 1    | Rounded square. |
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci## CheckBoxConfiguration<sup>12+</sup>
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ciYou need a custom class to implement the **ContentModifier** API.
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci| Name | Type   |    Default Value     |  Description             |
187e41f4b71Sopenharmony_ci| ------ | ------ | ------ |-------------------------------- |
188e41f4b71Sopenharmony_ci| name | string | - |Name of the check box. |
189e41f4b71Sopenharmony_ci| selected | boolean| false | Whether the check box is selected.<br>If the **select** attribute is not set, the default value **false** is used.<br>If the **select** attribute is set, the attribute value is used here. |
190e41f4b71Sopenharmony_ci| triggerChange |Callback\<boolean>| - |Changes the selected state of the check box. |
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci## Example
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci### Example 1
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci```ts
197e41f4b71Sopenharmony_ci// xxx.ets
198e41f4b71Sopenharmony_ci@Entry
199e41f4b71Sopenharmony_ci@Component
200e41f4b71Sopenharmony_cistruct CheckboxExample {
201e41f4b71Sopenharmony_ci  build() {
202e41f4b71Sopenharmony_ci    Flex({ justifyContent: FlexAlign.SpaceAround }) {
203e41f4b71Sopenharmony_ci      Checkbox({ name: 'checkbox1', group: 'checkboxGroup' })
204e41f4b71Sopenharmony_ci        .select(true)
205e41f4b71Sopenharmony_ci        .selectedColor(0xed6f21)
206e41f4b71Sopenharmony_ci        .shape(CheckBoxShape.CIRCLE)
207e41f4b71Sopenharmony_ci        .onChange((value: boolean) => {
208e41f4b71Sopenharmony_ci          console.info('Checkbox1 change is' + value)
209e41f4b71Sopenharmony_ci        })
210e41f4b71Sopenharmony_ci      Checkbox({ name: 'checkbox2', group: 'checkboxGroup' })
211e41f4b71Sopenharmony_ci        .select(false)
212e41f4b71Sopenharmony_ci        .selectedColor(0x39a2db)
213e41f4b71Sopenharmony_ci        .shape(CheckBoxShape.ROUNDED_SQUARE)
214e41f4b71Sopenharmony_ci        .onChange((value: boolean) => {
215e41f4b71Sopenharmony_ci          console.info('Checkbox2 change is' + value)
216e41f4b71Sopenharmony_ci        })
217e41f4b71Sopenharmony_ci    }
218e41f4b71Sopenharmony_ci  }
219e41f4b71Sopenharmony_ci}
220e41f4b71Sopenharmony_ci```
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci![](figures/checkbox.gif)
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci### Example 2
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ci```ts
228e41f4b71Sopenharmony_ci// xxx.ets
229e41f4b71Sopenharmony_ci@Entry
230e41f4b71Sopenharmony_ci@Component
231e41f4b71Sopenharmony_cistruct Index {
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci  build() {
234e41f4b71Sopenharmony_ci    Row() {
235e41f4b71Sopenharmony_ci      Column() {
236e41f4b71Sopenharmony_ci        Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
237e41f4b71Sopenharmony_ci          Checkbox({ name: 'checkbox1', group: 'checkboxGroup' })
238e41f4b71Sopenharmony_ci            .selectedColor(0x39a2db)
239e41f4b71Sopenharmony_ci            .shape(CheckBoxShape.ROUNDED_SQUARE)
240e41f4b71Sopenharmony_ci            .onChange((value: boolean) => {
241e41f4b71Sopenharmony_ci              console.info('Checkbox1 change is'+ value)
242e41f4b71Sopenharmony_ci            })
243e41f4b71Sopenharmony_ci            .mark({
244e41f4b71Sopenharmony_ci              strokeColor:Color.Black,
245e41f4b71Sopenharmony_ci              size: 50,
246e41f4b71Sopenharmony_ci              strokeWidth: 5
247e41f4b71Sopenharmony_ci            })
248e41f4b71Sopenharmony_ci            .unselectedColor(Color.Red)
249e41f4b71Sopenharmony_ci            .width(30)
250e41f4b71Sopenharmony_ci            .height(30)
251e41f4b71Sopenharmony_ci          Text('Checkbox1').fontSize(20)
252e41f4b71Sopenharmony_ci        }
253e41f4b71Sopenharmony_ci        Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
254e41f4b71Sopenharmony_ci          Checkbox({ name: 'checkbox2', group: 'checkboxGroup' })
255e41f4b71Sopenharmony_ci            .selectedColor(0x39a2db)
256e41f4b71Sopenharmony_ci            .shape(CheckBoxShape.ROUNDED_SQUARE)
257e41f4b71Sopenharmony_ci            .onChange((value: boolean) => {
258e41f4b71Sopenharmony_ci              console.info('Checkbox2 change is' + value)
259e41f4b71Sopenharmony_ci            })
260e41f4b71Sopenharmony_ci            .width(30)
261e41f4b71Sopenharmony_ci            .height(30)
262e41f4b71Sopenharmony_ci          Text('Checkbox2').fontSize(20)
263e41f4b71Sopenharmony_ci        }
264e41f4b71Sopenharmony_ci      }
265e41f4b71Sopenharmony_ci      .width('100%')
266e41f4b71Sopenharmony_ci    }
267e41f4b71Sopenharmony_ci    .height('100%')
268e41f4b71Sopenharmony_ci  }
269e41f4b71Sopenharmony_ci}
270e41f4b71Sopenharmony_ci```
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ci![](figures/checkbox2.gif)
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ci### Example 3
276e41f4b71Sopenharmony_ciThis example implements a custom check box. This check box comes in the custom pentagon style. When selected, the check box shows a red triangle pattern inside, and the title displays the word "Selected;" when deselected, the check box hides the red triangle pattern inside, and the title displays the word "Unselected."
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci```ts
279e41f4b71Sopenharmony_ci// xxx.ets
280e41f4b71Sopenharmony_ciclass MyCheckboxStyle implements ContentModifier<CheckBoxConfiguration> {
281e41f4b71Sopenharmony_ci  selectedColor: Color = Color.White
282e41f4b71Sopenharmony_ci  constructor(selectedColor: Color) {
283e41f4b71Sopenharmony_ci    this.selectedColor = selectedColor;
284e41f4b71Sopenharmony_ci  }
285e41f4b71Sopenharmony_ci  applyContent() : WrappedBuilder<[CheckBoxConfiguration]>
286e41f4b71Sopenharmony_ci  {
287e41f4b71Sopenharmony_ci    return wrapBuilder(buildCheckbox)
288e41f4b71Sopenharmony_ci  }
289e41f4b71Sopenharmony_ci}
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ci@Builder function buildCheckbox(config: CheckBoxConfiguration) {
292e41f4b71Sopenharmony_ci  Column({space:10}) {
293e41f4b71Sopenharmony_ci      Text(config.name  + (config.selected ? " (Selected)" : " (Unselected)")).margin({right : 70, top : 50})
294e41f4b71Sopenharmony_ci      Text(config.enabled ? "enabled true" : "enabled false").margin({right : 110})
295e41f4b71Sopenharmony_ci      Shape() {
296e41f4b71Sopenharmony_ci        Path().width(100).height(100).commands('M100 0 L0 100 L50 200 L150 200 L200 100 Z').fillOpacity(0).strokeWidth(3).onClick(()=>{
297e41f4b71Sopenharmony_ci          if (config.selected) {
298e41f4b71Sopenharmony_ci            config.triggerChange(false)
299e41f4b71Sopenharmony_ci          } else {
300e41f4b71Sopenharmony_ci            config.triggerChange(true)
301e41f4b71Sopenharmony_ci          }
302e41f4b71Sopenharmony_ci        }).opacity(config.enabled ? 1 : 0.1)
303e41f4b71Sopenharmony_ci        Path().width(10).height(10).commands('M50 0 L100 100 L0 100 Z')
304e41f4b71Sopenharmony_ci          .visibility(config.selected ? Visibility.Visible : Visibility.Hidden)
305e41f4b71Sopenharmony_ci          .fill(config.selected ? (config.contentModifier as MyCheckboxStyle).selectedColor : Color.Black)
306e41f4b71Sopenharmony_ci          .stroke((config.contentModifier as MyCheckboxStyle).selectedColor)
307e41f4b71Sopenharmony_ci          .margin({left:11,top:10})
308e41f4b71Sopenharmony_ci          .opacity(config.enabled ? 1 : 0.1)
309e41f4b71Sopenharmony_ci      }
310e41f4b71Sopenharmony_ci      .width(300)
311e41f4b71Sopenharmony_ci      .height(200)
312e41f4b71Sopenharmony_ci      .viewPort({ x: 0, y: 0, width: 310, height: 310 })
313e41f4b71Sopenharmony_ci      .strokeLineJoin(LineJoinStyle.Miter)
314e41f4b71Sopenharmony_ci      .strokeMiterLimit(5)
315e41f4b71Sopenharmony_ci      .margin({left:50})
316e41f4b71Sopenharmony_ci  }
317e41f4b71Sopenharmony_ci}
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci@Entry
320e41f4b71Sopenharmony_ci@Component
321e41f4b71Sopenharmony_cistruct Index {
322e41f4b71Sopenharmony_ci  @State checkboxEnabled: boolean = true;
323e41f4b71Sopenharmony_ci  build() {
324e41f4b71Sopenharmony_ci    Column({ space: 100 }) {
325e41f4b71Sopenharmony_ci        Checkbox({ name: 'Check box status', group: 'checkboxGroup' })
326e41f4b71Sopenharmony_ci        .contentModifier(new MyCheckboxStyle(Color.Red))
327e41f4b71Sopenharmony_ci        .onChange((value: boolean) => {
328e41f4b71Sopenharmony_ci          console.info('Checkbox change is' + value)
329e41f4b71Sopenharmony_ci        }).enabled(this.checkboxEnabled)
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci      Row() {
332e41f4b71Sopenharmony_ci        Toggle({ type: ToggleType.Switch, isOn: true }).onChange((value: boolean) => {
333e41f4b71Sopenharmony_ci          if (value) {
334e41f4b71Sopenharmony_ci            this.checkboxEnabled = true
335e41f4b71Sopenharmony_ci          } else {
336e41f4b71Sopenharmony_ci            this.checkboxEnabled = false
337e41f4b71Sopenharmony_ci          }
338e41f4b71Sopenharmony_ci        })
339e41f4b71Sopenharmony_ci      }
340e41f4b71Sopenharmony_ci    }.margin({top : 30})
341e41f4b71Sopenharmony_ci  }
342e41f4b71Sopenharmony_ci}
343e41f4b71Sopenharmony_ci```
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci
346e41f4b71Sopenharmony_ci![](figures/checkbox3.gif)
347e41f4b71Sopenharmony_ci
348e41f4b71Sopenharmony_ci### Example 4
349e41f4b71Sopenharmony_ciIn this example, a **Text** component is used to indicate that the check box is selected.
350e41f4b71Sopenharmony_ci```ts
351e41f4b71Sopenharmony_ci// xxx.ets
352e41f4b71Sopenharmony_ci@Entry
353e41f4b71Sopenharmony_ci@Component
354e41f4b71Sopenharmony_cistruct CheckboxExample {
355e41f4b71Sopenharmony_ci  @Builder
356e41f4b71Sopenharmony_ci  indicatorBuilder(value: number) {
357e41f4b71Sopenharmony_ci    Column(){
358e41f4b71Sopenharmony_ci      Text(value > 99 ? '99+': value.toString())
359e41f4b71Sopenharmony_ci        .textAlign(TextAlign.Center)
360e41f4b71Sopenharmony_ci        .fontSize(value > 99 ?  '16vp': '20vp')
361e41f4b71Sopenharmony_ci        .fontWeight(FontWeight.Medium)
362e41f4b71Sopenharmony_ci        .fontColor('#ffffffff')
363e41f4b71Sopenharmony_ci    }
364e41f4b71Sopenharmony_ci  }
365e41f4b71Sopenharmony_ci  build() {
366e41f4b71Sopenharmony_ci    Row() {
367e41f4b71Sopenharmony_ci      Column() {
368e41f4b71Sopenharmony_ci        Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center}) {
369e41f4b71Sopenharmony_ci          Checkbox({ name: 'checkbox1', group: 'checkboxGroup', indicatorBuilder:()=>{this.indicatorBuilder(9)}})
370e41f4b71Sopenharmony_ci            .shape(CheckBoxShape.CIRCLE)
371e41f4b71Sopenharmony_ci            .onChange((value: boolean) => {
372e41f4b71Sopenharmony_ci              console.info('Checkbox1 change is'+ value)
373e41f4b71Sopenharmony_ci            })
374e41f4b71Sopenharmony_ci            .mark({
375e41f4b71Sopenharmony_ci              strokeColor:Color.Black,
376e41f4b71Sopenharmony_ci              size: 50,
377e41f4b71Sopenharmony_ci              strokeWidth: 5
378e41f4b71Sopenharmony_ci            })
379e41f4b71Sopenharmony_ci            .width(30)
380e41f4b71Sopenharmony_ci            .height(30)
381e41f4b71Sopenharmony_ci          Text('Checkbox1').fontSize(20)
382e41f4b71Sopenharmony_ci        }.padding(15)
383e41f4b71Sopenharmony_ci        Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
384e41f4b71Sopenharmony_ci          Checkbox({ name: 'checkbox2', group: 'checkboxGroup', indicatorBuilder:()=>{this.indicatorBuilder(100)}})
385e41f4b71Sopenharmony_ci            .shape(CheckBoxShape.ROUNDED_SQUARE)
386e41f4b71Sopenharmony_ci            .onChange((value: boolean) => {
387e41f4b71Sopenharmony_ci              console.info('Checkbox2 change is' + value)
388e41f4b71Sopenharmony_ci            })
389e41f4b71Sopenharmony_ci            .width(30)
390e41f4b71Sopenharmony_ci            .height(30)
391e41f4b71Sopenharmony_ci          Text('Checkbox2').fontSize(20)
392e41f4b71Sopenharmony_ci        }
393e41f4b71Sopenharmony_ci      }
394e41f4b71Sopenharmony_ci      .width('100%')
395e41f4b71Sopenharmony_ci    }
396e41f4b71Sopenharmony_ci    .height('100%')
397e41f4b71Sopenharmony_ci  }
398e41f4b71Sopenharmony_ci}
399e41f4b71Sopenharmony_ci```
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci![](figures/checkbox4.gif)
403