1e41f4b71Sopenharmony_ci# Radio
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **Radio** component allows users to select from a set of mutually exclusive options.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciNot supported
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## APIs
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciRadio(options: RadioOptions)
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciCreates a radio button.
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 | [RadioOptions](#radiooptions)  | Yes  | Parameters of the radio button. |
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci## RadioOptions
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
36e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
37e41f4b71Sopenharmony_ci| value | string | Yes | Current value of the radio button.<br>**Atomic service API**: This API can be used in atomic services since API version 11. |
38e41f4b71Sopenharmony_ci| group | string | Yes | Name of the group to which the radio button belongs. Only one radio button in a given group can be selected at a time.<br>**Atomic service API**: This API can be used in atomic services since API version 11. |
39e41f4b71Sopenharmony_ci| indicatorType<sup>12+</sup> | [RadioIndicatorType](#radioindicatortype12)  | No | Indicator type of the radio button. If no value is specified, the value of **RadioIndicatorType.TICK** is used.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
40e41f4b71Sopenharmony_ci| indicatorBuilder<sup>12+</sup> | [CustomBuilder](ts-types.md#custombuilder8) | No | Custom component to indicate that the radio button is selected. This custom component is center aligned with the radio button. If this parameter is set to **undefined**, the value of **RadioIndicatorType.TICK** is used as the indicator type.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci## RadioIndicatorType<sup>12+</sup>
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci| Name           | Description                            |
47e41f4b71Sopenharmony_ci| --------------- | -------------------------------- |
48e41f4b71Sopenharmony_ci| TICK            | Default tick icon. |
49e41f4b71Sopenharmony_ci| DOT             | Default dot icon.  |
50e41f4b71Sopenharmony_ci| CUSTOM          | Custom component.|
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci## Attributes
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci### checked
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_cichecked(value: boolean)
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ciSets whether the radio button is selected.
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ciSince API version 10, this attribute supports two-way binding through [$$](../../../quick-start/arkts-two-way-sync.md).
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**Parameters** 
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                                |
73e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------ |
74e41f4b71Sopenharmony_ci| value  | boolean | Yes  | Whether the radio button is selected.<br>Default value: **false** |
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci### radioStyle<sup>10+</sup>
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ciradioStyle(value?: RadioStyle)
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ciSets the style of the radio button in selected or deselected state. 
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ciSince API version 10, this API is supported in ArkTS widgets.
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**Parameters** 
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci| Name | Type                               | Mandatory | Description                              |
91e41f4b71Sopenharmony_ci| ------ | ----------------------------------- | ---- | ---------------------------------- |
92e41f4b71Sopenharmony_ci| value  | [RadioStyle](#radiostyle10)  | No  | Style of the radio button in selected or deselected state. |
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci## contentModifier<sup>12+</sup>
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_cicontentModifier(modifier: ContentModifier\<RadioConfiguration>)
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ciCreates a content modifier.
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**Parameters**
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory | Description                                            |
107e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ------------------------------------------------ |
108e41f4b71Sopenharmony_ci| modifier  | [ContentModifier\<RadioConfiguration>](#radioconfiguration12)  | Yes  | Content modifier to apply to the current component.<br>**modifier**: content modifier. You need a custom class to implement the **ContentModifier** API. |
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci## Events
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ciIn addition to the [universal events](ts-universal-events-click.md), the following events are supported.
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci### onChange
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_cionChange(callback: (isChecked: boolean) => void)
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ciTriggered when the selected state of the radio button changes.
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci**Parameters** 
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci| Name   | Type   | Mandatory | Description                                                        |
129e41f4b71Sopenharmony_ci| --------- | ------- | ---- | ------------------------------------------------------------ |
130e41f4b71Sopenharmony_ci| isChecked | boolean | Yes  | Selected state of the radio button.<br>The value **true** means that the radio button changes from unselected to selected, and **false** means that the radio button changes from selected to unselected. |
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci## RadioStyle<sup>10+</sup>
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci| Name                  | Type                                      | Mandatory | Default Value | Description                  |
137e41f4b71Sopenharmony_ci| ---------------------- | ------------------------------------------ | ---- | ------- | ---------------------- |
138e41f4b71Sopenharmony_ci| checkedBackgroundColor | [ResourceColor](ts-types.md#resourcecolor) | No  | #007DFF | Color of the background when the radio button is selected.    |
139e41f4b71Sopenharmony_ci| uncheckedBorderColor   | [ResourceColor](ts-types.md#resourcecolor) | No  | #182431 | Color of the border when the radio button is deselected.    |
140e41f4b71Sopenharmony_ci| indicatorColor         | [ResourceColor](ts-types.md#resourcecolor) | No  | #FFFFFF | Color of the indicator when the radio button is selected. Since API version 12, this parameter takes effect only when **indicatorType** is set to **RadioIndicatorType.TICK** or **RadioIndicatorType.DOT**.   |
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci## RadioConfiguration<sup>12+</sup>
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ciYou need a custom class to implement the **ContentModifier** API.
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci| Name | Type   |    Default Value     |  Description             |
149e41f4b71Sopenharmony_ci| ------ | ------ | ------ |-------------------------------- |
150e41f4b71Sopenharmony_ci| value | string | - |Current value of the radio button. |
151e41f4b71Sopenharmony_ci| checked | boolean| false | Whether the radio button is selected.|
152e41f4b71Sopenharmony_ci| triggerChange |Callback\<boolean>| - |Changes the selected state of the radio button. |
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci## Example
156e41f4b71Sopenharmony_ci### Example 1 
157e41f4b71Sopenharmony_ciThis example shows how to set the color of the background when the radio button is selected.
158e41f4b71Sopenharmony_ci```ts
159e41f4b71Sopenharmony_ci// xxx.ets
160e41f4b71Sopenharmony_ci@Entry
161e41f4b71Sopenharmony_ci@Component
162e41f4b71Sopenharmony_cistruct RadioExample {
163e41f4b71Sopenharmony_ci  build() {
164e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
165e41f4b71Sopenharmony_ci      Column() {
166e41f4b71Sopenharmony_ci        Text('Radio1')
167e41f4b71Sopenharmony_ci        Radio({ value: 'Radio1', group: 'radioGroup' }).checked(true)
168e41f4b71Sopenharmony_ci          .radioStyle({
169e41f4b71Sopenharmony_ci            checkedBackgroundColor: Color.Pink
170e41f4b71Sopenharmony_ci          })
171e41f4b71Sopenharmony_ci          .height(50)
172e41f4b71Sopenharmony_ci          .width(50)
173e41f4b71Sopenharmony_ci          .onChange((isChecked: boolean) => {
174e41f4b71Sopenharmony_ci            console.log('Radio1 status is ' + isChecked)
175e41f4b71Sopenharmony_ci          })
176e41f4b71Sopenharmony_ci      }
177e41f4b71Sopenharmony_ci      Column() {
178e41f4b71Sopenharmony_ci        Text('Radio2')
179e41f4b71Sopenharmony_ci        Radio({ value: 'Radio2', group: 'radioGroup' }).checked(false)
180e41f4b71Sopenharmony_ci          .radioStyle({
181e41f4b71Sopenharmony_ci            checkedBackgroundColor: Color.Pink
182e41f4b71Sopenharmony_ci          })
183e41f4b71Sopenharmony_ci          .height(50)
184e41f4b71Sopenharmony_ci          .width(50)
185e41f4b71Sopenharmony_ci          .onChange((isChecked: boolean) => {
186e41f4b71Sopenharmony_ci            console.log('Radio2 status is ' + isChecked)
187e41f4b71Sopenharmony_ci          })
188e41f4b71Sopenharmony_ci      }
189e41f4b71Sopenharmony_ci      Column() {
190e41f4b71Sopenharmony_ci        Text('Radio3')
191e41f4b71Sopenharmony_ci        Radio({ value: 'Radio3', group: 'radioGroup' }).checked(false)
192e41f4b71Sopenharmony_ci          .radioStyle({
193e41f4b71Sopenharmony_ci            checkedBackgroundColor: Color.Pink
194e41f4b71Sopenharmony_ci          })
195e41f4b71Sopenharmony_ci          .height(50)
196e41f4b71Sopenharmony_ci          .width(50)
197e41f4b71Sopenharmony_ci          .onChange((isChecked: boolean) => {
198e41f4b71Sopenharmony_ci            console.log('Radio3 status is ' + isChecked)
199e41f4b71Sopenharmony_ci          })
200e41f4b71Sopenharmony_ci      }
201e41f4b71Sopenharmony_ci    }.padding({ top: 30 })
202e41f4b71Sopenharmony_ci  }
203e41f4b71Sopenharmony_ci}
204e41f4b71Sopenharmony_ci```
205e41f4b71Sopenharmony_ci![radio](figures/radio.gif)
206e41f4b71Sopenharmony_ci### Example 2 
207e41f4b71Sopenharmony_ciThis example shows how to set the indicator of the radio button to an image.
208e41f4b71Sopenharmony_ci```ts
209e41f4b71Sopenharmony_ci// xxx.ets
210e41f4b71Sopenharmony_ci@Entry
211e41f4b71Sopenharmony_ci@Component
212e41f4b71Sopenharmony_cistruct RadioExample {
213e41f4b71Sopenharmony_ci  @Builder 
214e41f4b71Sopenharmony_ci  indicatorBuilder() {
215e41f4b71Sopenharmony_ci    Image($r("app.media.star"))
216e41f4b71Sopenharmony_ci  }
217e41f4b71Sopenharmony_ci  build() {
218e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
219e41f4b71Sopenharmony_ci      Column() {
220e41f4b71Sopenharmony_ci        Text('Radio1')
221e41f4b71Sopenharmony_ci        Radio({ value: 'Radio1', group: 'radioGroup',
222e41f4b71Sopenharmony_ci          indicatorType:RadioIndicatorType.TICK
223e41f4b71Sopenharmony_ci        }).checked(true)
224e41f4b71Sopenharmony_ci          .height(50)
225e41f4b71Sopenharmony_ci          .width(80)
226e41f4b71Sopenharmony_ci          .onChange((isChecked: boolean) => {
227e41f4b71Sopenharmony_ci            console.log('Radio1 status is ' + isChecked)
228e41f4b71Sopenharmony_ci          })
229e41f4b71Sopenharmony_ci      }
230e41f4b71Sopenharmony_ci      Column() {
231e41f4b71Sopenharmony_ci        Text('Radio2')
232e41f4b71Sopenharmony_ci        Radio({ value: 'Radio2', group: 'radioGroup',
233e41f4b71Sopenharmony_ci          indicatorType:RadioIndicatorType.DOT
234e41f4b71Sopenharmony_ci        }).checked(false)
235e41f4b71Sopenharmony_ci          .height(50)
236e41f4b71Sopenharmony_ci          .width(80)
237e41f4b71Sopenharmony_ci          .onChange((isChecked: boolean) => {
238e41f4b71Sopenharmony_ci            console.log('Radio2 status is ' + isChecked)
239e41f4b71Sopenharmony_ci          })
240e41f4b71Sopenharmony_ci      }
241e41f4b71Sopenharmony_ci      Column() {
242e41f4b71Sopenharmony_ci        Text('Radio3')
243e41f4b71Sopenharmony_ci        Radio({ value: 'Radio3', group: 'radioGroup',
244e41f4b71Sopenharmony_ci          indicatorType:RadioIndicatorType.CUSTOM,
245e41f4b71Sopenharmony_ci          indicatorBuilder:()=>{this.indicatorBuilder()}
246e41f4b71Sopenharmony_ci        }).checked(false)
247e41f4b71Sopenharmony_ci          .height(50)
248e41f4b71Sopenharmony_ci          .width(80)
249e41f4b71Sopenharmony_ci          .onChange((isChecked: boolean) => {
250e41f4b71Sopenharmony_ci            console.log('Radio3 status is ' + isChecked)
251e41f4b71Sopenharmony_ci          })
252e41f4b71Sopenharmony_ci      }
253e41f4b71Sopenharmony_ci    }.padding({ top: 30 })
254e41f4b71Sopenharmony_ci  }
255e41f4b71Sopenharmony_ci}
256e41f4b71Sopenharmony_ci```
257e41f4b71Sopenharmony_ci![radio](figures/radio_2.gif)
258e41f4b71Sopenharmony_ci### Example 3
259e41f4b71Sopenharmony_ciThis example shows how to set the style of the radio button in selected or deselected state.
260e41f4b71Sopenharmony_ci```ts
261e41f4b71Sopenharmony_ciclass MyRadioStyle implements ContentModifier<RadioConfiguration> {
262e41f4b71Sopenharmony_ci  type: number = 0
263e41f4b71Sopenharmony_ci  selectedColor:Color = Color.Black
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ci  constructor(numberType: number, colorType:Color) {
266e41f4b71Sopenharmony_ci    this.type = numberType
267e41f4b71Sopenharmony_ci    this.selectedColor = colorType
268e41f4b71Sopenharmony_ci  }
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ci  applyContent() : WrappedBuilder<[RadioConfiguration]>
271e41f4b71Sopenharmony_ci  {
272e41f4b71Sopenharmony_ci    return wrapBuilder(buildRadio)
273e41f4b71Sopenharmony_ci  }
274e41f4b71Sopenharmony_ci}
275e41f4b71Sopenharmony_ci
276e41f4b71Sopenharmony_ci@Builder function buildRadio(config: RadioConfiguration) {
277e41f4b71Sopenharmony_ci  Row({ space:30 }) {
278e41f4b71Sopenharmony_ci    Circle({ width: 50, height: 50 })
279e41f4b71Sopenharmony_ci      .stroke(Color.Black)
280e41f4b71Sopenharmony_ci      .fill(config.checked ? (config.contentModifier as MyRadioStyle).selectedColor : Color.White)
281e41f4b71Sopenharmony_ci    Button(config.checked ? "off" : "on")
282e41f4b71Sopenharmony_ci      .width(100)
283e41f4b71Sopenharmony_ci      .type(config.checked ? (config.contentModifier as MyRadioStyle).type : ButtonType.Normal)
284e41f4b71Sopenharmony_ci      .backgroundColor(0xAABBCC)
285e41f4b71Sopenharmony_ci      .onClick(()=>{
286e41f4b71Sopenharmony_ci        if (config.checked) {
287e41f4b71Sopenharmony_ci          config.triggerChange(false)
288e41f4b71Sopenharmony_ci        } else {
289e41f4b71Sopenharmony_ci          config.triggerChange(true)
290e41f4b71Sopenharmony_ci        }
291e41f4b71Sopenharmony_ci      })
292e41f4b71Sopenharmony_ci  }
293e41f4b71Sopenharmony_ci}
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci@Entry
296e41f4b71Sopenharmony_ci@Component
297e41f4b71Sopenharmony_cistruct refreshExample {
298e41f4b71Sopenharmony_ci  build() {
299e41f4b71Sopenharmony_ci    Column({ space: 50 }) {
300e41f4b71Sopenharmony_ci      Row() {
301e41f4b71Sopenharmony_ci        Radio({ value: 'Radio1', group: 'radioGroup' })
302e41f4b71Sopenharmony_ci          .contentModifier(new MyRadioStyle(1, Color.Red))
303e41f4b71Sopenharmony_ci          .checked(false)
304e41f4b71Sopenharmony_ci          .width(300)
305e41f4b71Sopenharmony_ci          .height(100)
306e41f4b71Sopenharmony_ci      }
307e41f4b71Sopenharmony_ci      Row() {
308e41f4b71Sopenharmony_ci        Radio({ value: 'Radio2', group: 'radioGroup' })
309e41f4b71Sopenharmony_ci          .checked(true)
310e41f4b71Sopenharmony_ci          .width(300)
311e41f4b71Sopenharmony_ci          .height(60)
312e41f4b71Sopenharmony_ci          .contentModifier(new MyRadioStyle(2, Color.Red))
313e41f4b71Sopenharmony_ci      }
314e41f4b71Sopenharmony_ci    }
315e41f4b71Sopenharmony_ci  }
316e41f4b71Sopenharmony_ci}
317e41f4b71Sopenharmony_ci```
318e41f4b71Sopenharmony_ci![](figures/radio_3.gif)
319