1e41f4b71Sopenharmony_ci# Button
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **Button** component can be used to create different types of buttons.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciThis component can contain only one child component.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## APIs
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci### Button
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciButton(options: ButtonOptions)
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciCreates a button that can contain a single child component.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**Parameters** 
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| Name | Type                                   | Mandatory | Description                |
32e41f4b71Sopenharmony_ci| ------- | --------------------------------------- | ---- | -------------------- |
33e41f4b71Sopenharmony_ci| options | [ButtonOptions](#buttonoptions)  | Yes  | Button settings. |
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci### Button
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ciButton(label: ResourceStr, options?: ButtonOptions)
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ciCreates a button based on text content. In this case, the component cannot contain child components.
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ciBy default, the text content is displayed in a one line.
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**Parameters** 
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci| Name | Type                                   | Mandatory | Description                |
52e41f4b71Sopenharmony_ci| ------- | --------------------------------------- | ---- | -------------------- |
53e41f4b71Sopenharmony_ci| label   | [ResourceStr](ts-types.md#resourcestr)  | Yes  | Button text.      |
54e41f4b71Sopenharmony_ci| options | [ButtonOptions](#buttonoptions)  | No  | Button settings. |
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci## ButtonOptions
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci| Name                     | Type                                         | Mandatory | Description                                                        |
59e41f4b71Sopenharmony_ci| ------------------------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
60e41f4b71Sopenharmony_ci| type                      | [ButtonType](#buttontype)             | No  | Button type.<br>Default value: **ButtonType.Capsule**<br>**Atomic service API**: This API can be used in atomic services since API version 11.           |
61e41f4b71Sopenharmony_ci| stateEffect               | boolean                                       | No  | Whether to enable the pressed effect on the click of the button. The value **false** means to disable the pressed effect.<br>Default value: **true**<br>**NOTE**<br>When the pressed effect is enabled on the click of the button and the state style is set, the background color is applied based on the state style.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
62e41f4b71Sopenharmony_ci| buttonStyle<sup>11+</sup> | [ButtonStyleMode](#buttonstylemode11)  | No  | Style and primacy of the button.<br>Default value: **ButtonStyleMode.EMPHASIZED**<br>**NOTE**<br>The button primacy is as follows, from high to low: emphasized button, normal button, text button.<br>**Atomic service API**: This API can be used in atomic services since API version 12. |
63e41f4b71Sopenharmony_ci| controlSize<sup>11+</sup> | [ControlSize](#controlsize11)         | No  | Size of the button.<br>Default value: **ControlSize.NORMAL**<br>**Atomic service API**: This API can be used in atomic services since API version 12.             |
64e41f4b71Sopenharmony_ci| role<sup>12+</sup> | [ButtonRole](#buttonrole12)         | No  | Role of the button.<br>Default value: **ButtonRole.NORMAL**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci## Attributes
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci### type
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_citype(value: ButtonType)
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ciSets the button type.
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**Parameters** 
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci| Name | Type                             | Mandatory | Description                                       |
85e41f4b71Sopenharmony_ci| ------ | --------------------------------- | ---- | ------------------------------------------- |
86e41f4b71Sopenharmony_ci| value  | [ButtonType](#buttontype)  | Yes  | Button type.<br>Default value: **ButtonType.Capsule** |
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci### fontSize
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_cifontSize(value: Length)
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ciSets the font size for the button.
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci**Parameters** 
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci| Name | Type                        | Mandatory | Description                             |
103e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | --------------------------------- |
104e41f4b71Sopenharmony_ci| value  | [Length](ts-types.md#length) | Yes  | Font size of the button.<br>Default value: **'16fp'** if **controlSize** is set to **controlSize.NORMAL** and **'12fp'** if **controlSize** is set to **controlSize.SMALL** |
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci### fontColor
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_cifontColor(value: ResourceColor)
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ciSets the font color for the button.
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci**Parameters** 
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci| Name | Type                                      | Mandatory | Description                                 |
121e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ------------------------------------- |
122e41f4b71Sopenharmony_ci| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Font color of the button.<br>Default value: **'\#ffffff'** |
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci### fontWeight
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_cifontWeight(value: number | FontWeight | string)
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ciSets the font weight for the button.
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci**Parameters** 
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci| Name | Type                                                        | Mandatory | Description                                                        |
139e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
140e41f4b71Sopenharmony_ci| value  | [FontWeight](ts-appendix-enums.md#fontweight) \| number \| string | Yes  | Font weight of the button. For the number type, the value ranges from 100 to 900, at an interval of 100. A larger value indicates a thicker font.<br>Default value: **400** |
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci### fontStyle
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_cifontStyle(value: FontStyle)
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ciSets the font style for the button.
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**Parameters** 
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci| Name | Type                                       | Mandatory | Description                                           |
157e41f4b71Sopenharmony_ci| ------ | ------------------------------------------- | ---- | ----------------------------------------------- |
158e41f4b71Sopenharmony_ci| value  | [FontStyle](ts-appendix-enums.md#fontstyle) | Yes  | Font style of the button.<br>Default value: **FontStyle.Normal** |
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci### stateEffect
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_cistateEffect(value: boolean)
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ciSpecifies whether to enable the pressed effect on the click of the button.
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci**Parameters** 
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                                                        |
175e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ |
176e41f4b71Sopenharmony_ci| value  | boolean | Yes  | Whether to enable the pressed effect on the click of the button. The value **false** means to disable the pressed effect.<br>Default value: **true** |
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci### fontFamily
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_cifontFamily(value: string | Resource)
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ciSets the font family.
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci**Parameters** 
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci| Name | Type                                                | Mandatory | Description                                                        |
193e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
194e41f4b71Sopenharmony_ci| value  | [Resource](ts-types.md#resource) \| string | Yes  | Font family. The 'HarmonyOS Sans' font and [registered custom fonts](../js-apis-font.md) are supported. |
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci### labelStyle<sup>10+</sup>
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_cilabelStyle(value: LabelStyle)
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ciSets the label style for the button.
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_ci**Parameters** 
207e41f4b71Sopenharmony_ci
208e41f4b71Sopenharmony_ci| Name | Type                               | Mandatory | Description                             |
209e41f4b71Sopenharmony_ci| ------ | ----------------------------------- | ---- | --------------------------------- |
210e41f4b71Sopenharmony_ci| value  | [LabelStyle](#labelstyle10)  | Yes  | Label style of the button. |
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci### buttonStyle<sup>11+</sup>
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_cibuttonStyle(value: ButtonStyleMode)
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ciSets the style and primacy for the button.
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 11.
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci**Parameters** 
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory | Description                                                        |
227e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ------------------------------------------------------------ |
228e41f4b71Sopenharmony_ci| value  | [ButtonStyleMode](#buttonstylemode11)  | Yes  | Style and primacy of the button<br>Default value: **ButtonStyleMode.EMPHASIZED** |
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci### controlSize<sup>11+</sup>
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_cicontrolSize(value: ControlSize)
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ciSets the size for the button.
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 11.
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**Parameters** 
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci| Name | Type                                 | Mandatory | Description                                            |
245e41f4b71Sopenharmony_ci| ------ | ------------------------------------- | ---- | ------------------------------------------------ |
246e41f4b71Sopenharmony_ci| value  | [ControlSize](#controlsize11)  | Yes  | Size of the button.<br>Default value: **ControlSize.NORMAL** |
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci### role<sup>12+</sup>
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_cirole(value: ButtonRole)
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ciSets the role of the button.
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_ci**Parameters** 
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory | Description                                            |
263e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ------------------------------------------------ |
264e41f4b71Sopenharmony_ci| value  | [ButtonRole](#buttonrole12)  | Yes  | Role of the button.<br>Default value: **ButtonRole.NORMAL** |
265e41f4b71Sopenharmony_ci
266e41f4b71Sopenharmony_ci### contentModifier<sup>12+</sup>
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_cicontentModifier(modifier: ContentModifier\<ButtonConfiguration>)
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ciCreates a content modifier.
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
273e41f4b71Sopenharmony_ci
274e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
275e41f4b71Sopenharmony_ci
276e41f4b71Sopenharmony_ci**Parameters**
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci| Name | Type                                         | Mandatory | Description                                            |
279e41f4b71Sopenharmony_ci| ------ | --------------------------------------------- | ---- | ------------------------------------------------ |
280e41f4b71Sopenharmony_ci| modifier  | [ContentModifier\<ButtonConfiguration>](#buttonconfiguration12)  | Yes  | Content modifier to apply to the button.<br>**modifier**: content modifier. You need a custom class to implement the **ContentModifier** API. |
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci## ButtonType
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci| Name     | Description                |
289e41f4b71Sopenharmony_ci| ------- | ------------------ |
290e41f4b71Sopenharmony_ci| Capsule | Capsule-type button (the round corner is half of the height by default). |
291e41f4b71Sopenharmony_ci| Circle  | Circle button.             |
292e41f4b71Sopenharmony_ci| Normal  | Normal button (without rounded corners by default).     |
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci>  **NOTE**
295e41f4b71Sopenharmony_ci>  - The rounded corner of a button is set by using [borderRadius](ts-universal-attributes-border.md#borderradius), rather than by using the **border** API. Only a rounded corner whose parameter is [Length](ts-types.md#length) is supported.
296e41f4b71Sopenharmony_ci>  - For a button of the **Capsule** type, the **borderRadius** settings do not take effect, and the radius of its rounded corner is always half of the button height or width, whichever is smaller.
297e41f4b71Sopenharmony_ci>  - For a button of the **Circle** type: (1) If both its width and height are set, **borderRadius** does not take effect, and the button radius is half of the width or height (whichever is smaller). (2) If either its width or height is set, **borderRadius** does not take effect, and the button radius is half of the set width or height. (3) If neither its width nor height is set, the button radius is as specified by **borderRadius**; if **borderRadius** is set to a negative value, the value **0** will be used.
298e41f4b71Sopenharmony_ci>  - The button text is set using the [text style attributes](ts-universal-attributes-text-style.md#attributes).
299e41f4b71Sopenharmony_ci>  - Before setting the [gradient color](ts-universal-attributes-gradient-color.md), you need to set [backgroundColor](ts-universal-attributes-background.md#backgroundcolor) to transparent.
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci## LabelStyle<sup>10+</sup>
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ci| Name                | Type                                                    | Mandatory | Description                                                        |
306e41f4b71Sopenharmony_ci| -------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
307e41f4b71Sopenharmony_ci| overflow             | [TextOverflow](ts-appendix-enums.md#textoverflow)            | No  | Display mode when the label text is too long. Text is clipped at the transition between words. To clip text in the middle of a word, add zero-width spaces between characters.<br>Default value: **TextOverflow.Ellipsis** |
308e41f4b71Sopenharmony_ci| maxLines             | number                                                       | No  | Maximum number of lines in the label text. By default, text is automatically folded. If this attribute is specified, the text will not exceed the specified number of lines. If there is extra text, you can use **overflow** to specify how it is displayed.<br>Default value: **1** |
309e41f4b71Sopenharmony_ci| minFontSize          | number \| [ResourceStr](ts-types.md#resourcestr)             | No  | Minimum font size of the label text. For the setting to take effect, this attribute must be used together with **maxFontSize**, **maxLines**, or layout constraint settings.<br>**NOTE**<br>If the value of **minFontSize** is less than or equal to 0, the adaptive font size does not take effect. |
310e41f4b71Sopenharmony_ci| maxFontSize          | number \| [ResourceStr](ts-types.md#resourcestr)             | No  | Maximum font size of the label text. For the setting to take effect, this attribute must be used together with **minFontSize**, **maxLines**, or layout constraint settings. |
311e41f4b71Sopenharmony_ci| heightAdaptivePolicy | [TextHeightAdaptivePolicy](ts-appendix-enums.md#textheightadaptivepolicy10) | No  | How the adaptive height is determined for the label text.<br>Default value: **TextHeightAdaptivePolicy.MAX_LINES_FIRST** |
312e41f4b71Sopenharmony_ci| font                 | [Font](ts-types.md#font)                                     | No  | Font of the label text.<br>Default value: See [Font](ts-types.md#font). |
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci## ButtonStyleMode<sup>11+</sup>
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 11.
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci| Name     | Description                |
321e41f4b71Sopenharmony_ci| ------- | ------------------ |
322e41f4b71Sopenharmony_ci| EMPHASIZED | Emphasized button (used to direct the user to the most important task). |
323e41f4b71Sopenharmony_ci| NORMAL  | Normal button (used to direct the user to a common task).             |
324e41f4b71Sopenharmony_ci| TEXTUAL  | Text button (displayed as simple text without any background color).     |
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci## ControlSize<sup>11+</sup>
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 11.
329e41f4b71Sopenharmony_ci
330e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
331e41f4b71Sopenharmony_ci
332e41f4b71Sopenharmony_ci| Name     | Description                |
333e41f4b71Sopenharmony_ci| ------- | ------------------ |
334e41f4b71Sopenharmony_ci| SMALL | Small button. |
335e41f4b71Sopenharmony_ci| NORMAL  | Normal button.             |
336e41f4b71Sopenharmony_ci
337e41f4b71Sopenharmony_ci## ButtonRole<sup>12+</sup>
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci| Name     | Description                |
344e41f4b71Sopenharmony_ci| ------- | ------------------ |
345e41f4b71Sopenharmony_ci| NORMAL | Normal button. |
346e41f4b71Sopenharmony_ci| ERROR  | Warning button.             |
347e41f4b71Sopenharmony_ci
348e41f4b71Sopenharmony_ci## ButtonConfiguration<sup>12+</sup>
349e41f4b71Sopenharmony_ci
350e41f4b71Sopenharmony_ciYou need a custom class to implement the **ContentModifier** API.
351e41f4b71Sopenharmony_ci
352e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_ci| Name | Type   | Description             |
355e41f4b71Sopenharmony_ci| ------ | ------ | ---------------- |
356e41f4b71Sopenharmony_ci| label | string | Text label of the button. |
357e41f4b71Sopenharmony_ci| pressed | boolean | Whether the button is pressed.<br>**NOTE**<br>The button here refers to the original button, not the new component constructed using the builder. If the new component is larger than the original button, this parameter does not signify the pressed state of the excess part. |
358e41f4b71Sopenharmony_ci| triggerClick | [ButtonTriggerClickCallback](#buttontriggerclickcallback12)  | Click event of the new component constructed using the builder. |
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_ci## ButtonTriggerClickCallback<sup>12+</sup>
361e41f4b71Sopenharmony_ci
362e41f4b71Sopenharmony_ciDefines the callback type used in **ButtonConfiguration**.
363e41f4b71Sopenharmony_ci
364e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description             |
367e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------- |
368e41f4b71Sopenharmony_ci| xPos | number | Yes | X-coordinate of the click point. |
369e41f4b71Sopenharmony_ci| yPos | number | Yes | Y-coordinate of the click point. |
370e41f4b71Sopenharmony_ci
371e41f4b71Sopenharmony_ci## Events
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_ciThe [universal events](ts-universal-events-click.md) are supported.
374e41f4b71Sopenharmony_ci## Example
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ci### Example 1
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci```ts
379e41f4b71Sopenharmony_ci// xxx.ets
380e41f4b71Sopenharmony_ci@Entry
381e41f4b71Sopenharmony_ci@Component
382e41f4b71Sopenharmony_cistruct ButtonExample {
383e41f4b71Sopenharmony_ci  build() {
384e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
385e41f4b71Sopenharmony_ci      Text('Normal button').fontSize(9).fontColor(0xCCCCCC)
386e41f4b71Sopenharmony_ci      Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
387e41f4b71Sopenharmony_ci        Button('OK', { type: ButtonType.Normal, stateEffect: true })
388e41f4b71Sopenharmony_ci          .borderRadius(8)
389e41f4b71Sopenharmony_ci          .backgroundColor(0x317aff)
390e41f4b71Sopenharmony_ci          .width(90)
391e41f4b71Sopenharmony_ci          .onClick(() => {
392e41f4b71Sopenharmony_ci            console.log('ButtonType.Normal')
393e41f4b71Sopenharmony_ci          })
394e41f4b71Sopenharmony_ci        Button({ type: ButtonType.Normal, stateEffect: true }) {
395e41f4b71Sopenharmony_ci          Row() {
396e41f4b71Sopenharmony_ci            LoadingProgress().width(20).height(20).margin({ left: 12 }).color(0xFFFFFF)
397e41f4b71Sopenharmony_ci            Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 })
398e41f4b71Sopenharmony_ci          }.alignItems(VerticalAlign.Center)
399e41f4b71Sopenharmony_ci        }.borderRadius(8).backgroundColor(0x317aff).width(90).height(40)
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ci        Button('Disable', { type: ButtonType.Normal, stateEffect: false }).opacity(0.4)
402e41f4b71Sopenharmony_ci          .borderRadius(8).backgroundColor(0x317aff).width(90)
403e41f4b71Sopenharmony_ci      }
404e41f4b71Sopenharmony_ci
405e41f4b71Sopenharmony_ci      Text('Capsule button').fontSize(9).fontColor(0xCCCCCC)
406e41f4b71Sopenharmony_ci      Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
407e41f4b71Sopenharmony_ci        Button('OK', { type: ButtonType.Capsule, stateEffect: true }).backgroundColor(0x317aff).width(90)
408e41f4b71Sopenharmony_ci        Button({ type: ButtonType.Capsule, stateEffect: true }) {
409e41f4b71Sopenharmony_ci          Row() {
410e41f4b71Sopenharmony_ci            LoadingProgress().width(20).height(20).margin({ left: 12 }).color(0xFFFFFF)
411e41f4b71Sopenharmony_ci            Text('loading').fontSize(12).fontColor(0xffffff).margin({ left: 5, right: 12 })
412e41f4b71Sopenharmony_ci          }.alignItems(VerticalAlign.Center).width(90).height(40)
413e41f4b71Sopenharmony_ci        }.backgroundColor(0x317aff)
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ci        Button('Disable', { type: ButtonType.Capsule, stateEffect: false }).opacity(0.4)
416e41f4b71Sopenharmony_ci          .backgroundColor(0x317aff).width(90)
417e41f4b71Sopenharmony_ci      }
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ci      Text('Circle button').fontSize(9).fontColor(0xCCCCCC)
420e41f4b71Sopenharmony_ci      Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.Wrap }) {
421e41f4b71Sopenharmony_ci        Button({ type: ButtonType.Circle, stateEffect: true }) {
422e41f4b71Sopenharmony_ci          LoadingProgress().width(20).height(20).color(0xFFFFFF)
423e41f4b71Sopenharmony_ci        }.width(55).height(55).backgroundColor(0x317aff)
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_ci        Button({ type: ButtonType.Circle, stateEffect: true }) {
426e41f4b71Sopenharmony_ci          LoadingProgress().width(20).height(20).color(0xFFFFFF)
427e41f4b71Sopenharmony_ci        }.width(55).height(55).margin({ left: 20 }).backgroundColor(0xF55A42)
428e41f4b71Sopenharmony_ci      }
429e41f4b71Sopenharmony_ci    }.height(400).padding({ left: 35, right: 35, top: 35 })
430e41f4b71Sopenharmony_ci  }
431e41f4b71Sopenharmony_ci}
432e41f4b71Sopenharmony_ci```
433e41f4b71Sopenharmony_ci
434e41f4b71Sopenharmony_ci![button](figures/button.gif)
435e41f4b71Sopenharmony_ci
436e41f4b71Sopenharmony_ci### Example 2 
437e41f4b71Sopenharmony_ci
438e41f4b71Sopenharmony_ci```ts
439e41f4b71Sopenharmony_ci// xxx.ets
440e41f4b71Sopenharmony_ci@Entry
441e41f4b71Sopenharmony_ci@Component
442e41f4b71Sopenharmony_cistruct SwipeGestureExample {
443e41f4b71Sopenharmony_ci  @State count: number = 0
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_ci  build() {
446e41f4b71Sopenharmony_ci    Column() {
447e41f4b71Sopenharmony_ci      Text(`${this.count}`)
448e41f4b71Sopenharmony_ci        .fontSize(30)
449e41f4b71Sopenharmony_ci        .onClick(() => {
450e41f4b71Sopenharmony_ci          this.count++
451e41f4b71Sopenharmony_ci        })
452e41f4b71Sopenharmony_ci      if (this.count <= 0) {
453e41f4b71Sopenharmony_ci        Button('count is negative').fontSize(30).height(50)
454e41f4b71Sopenharmony_ci      } else if (this.count % 2 === 0) {
455e41f4b71Sopenharmony_ci        Button('count is even').fontSize(30).height(50)
456e41f4b71Sopenharmony_ci      } else {
457e41f4b71Sopenharmony_ci        Button('count is odd').fontSize(30).height(50)
458e41f4b71Sopenharmony_ci      }
459e41f4b71Sopenharmony_ci    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
460e41f4b71Sopenharmony_ci  }
461e41f4b71Sopenharmony_ci}
462e41f4b71Sopenharmony_ci```
463e41f4b71Sopenharmony_ci
464e41f4b71Sopenharmony_ci![ifButton](figures/ifButton.gif)
465e41f4b71Sopenharmony_ci
466e41f4b71Sopenharmony_ci### Example 3 
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_ci```ts
469e41f4b71Sopenharmony_ci// xxx.ets
470e41f4b71Sopenharmony_ci@Entry
471e41f4b71Sopenharmony_ci@Component
472e41f4b71Sopenharmony_cistruct buttonTestDemo {
473e41f4b71Sopenharmony_ci  @State txt: string = 'overflowTextOverlengthTextOverflow.Clip';
474e41f4b71Sopenharmony_ci  @State widthShortSize: number = 200;
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci  build() {
477e41f4b71Sopenharmony_ci    Row() {
478e41f4b71Sopenharmony_ci      Column() {
479e41f4b71Sopenharmony_ci        Button(this.txt)
480e41f4b71Sopenharmony_ci          .width(this.widthShortSize)
481e41f4b71Sopenharmony_ci          .height(100)
482e41f4b71Sopenharmony_ci          .labelStyle({ overflow: TextOverflow.Clip,
483e41f4b71Sopenharmony_ci            maxLines: 1,
484e41f4b71Sopenharmony_ci            minFontSize: 20,
485e41f4b71Sopenharmony_ci            maxFontSize: 20,
486e41f4b71Sopenharmony_ci            font: {
487e41f4b71Sopenharmony_ci              size: 20,
488e41f4b71Sopenharmony_ci              weight: FontWeight.Bolder,
489e41f4b71Sopenharmony_ci              family: 'cursive',
490e41f4b71Sopenharmony_ci              style: FontStyle.Italic
491e41f4b71Sopenharmony_ci            }
492e41f4b71Sopenharmony_ci          })
493e41f4b71Sopenharmony_ci          .fontSize(40)
494e41f4b71Sopenharmony_ci      }
495e41f4b71Sopenharmony_ci      .width('100%')
496e41f4b71Sopenharmony_ci    }
497e41f4b71Sopenharmony_ci    .height('100%')
498e41f4b71Sopenharmony_ci  }
499e41f4b71Sopenharmony_ci}
500e41f4b71Sopenharmony_ci```
501e41f4b71Sopenharmony_ci
502e41f4b71Sopenharmony_ci![image-20230711171138661](figures/imageButtonLabelStyle.png)
503e41f4b71Sopenharmony_ci
504e41f4b71Sopenharmony_ci### Example 4
505e41f4b71Sopenharmony_ci```ts
506e41f4b71Sopenharmony_ci// xxx.ets
507e41f4b71Sopenharmony_ci@Entry
508e41f4b71Sopenharmony_ci@Component
509e41f4b71Sopenharmony_cistruct ButtonExample {
510e41f4b71Sopenharmony_ci  build() {
511e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
512e41f4b71Sopenharmony_ci      Text('Normal size button').fontSize(9).fontColor(0xCCCCCC)
513e41f4b71Sopenharmony_ci      Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
514e41f4b71Sopenharmony_ci        Button('Emphasized', { buttonStyle: ButtonStyleMode.EMPHASIZED });
515e41f4b71Sopenharmony_ci        Button('Normal', { buttonStyle: ButtonStyleMode.NORMAL });
516e41f4b71Sopenharmony_ci        Button('Textual', { buttonStyle: ButtonStyleMode.TEXTUAL });
517e41f4b71Sopenharmony_ci      }
518e41f4b71Sopenharmony_ci
519e41f4b71Sopenharmony_ci      Text('Small size button').fontSize(9).fontColor(0xCCCCCC)
520e41f4b71Sopenharmony_ci      Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
521e41f4b71Sopenharmony_ci        Button('Emphasized', { controlSize: ControlSize.SMALL, buttonStyle: ButtonStyleMode.EMPHASIZED });
522e41f4b71Sopenharmony_ci        Button('Normal', { controlSize: ControlSize.SMALL, buttonStyle: ButtonStyleMode.NORMAL });
523e41f4b71Sopenharmony_ci        Button('Textual', { controlSize: ControlSize.SMALL, buttonStyle: ButtonStyleMode.TEXTUAL });
524e41f4b71Sopenharmony_ci      }
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci      Text('Small size button').fontSize(9).fontColor(0xCCCCCC)
527e41f4b71Sopenharmony_ci      Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
528e41f4b71Sopenharmony_ci        Button('Emphasized').controlSize(ControlSize.SMALL).buttonStyle(ButtonStyleMode.EMPHASIZED);
529e41f4b71Sopenharmony_ci        Button('Normal').controlSize(ControlSize.SMALL).buttonStyle(ButtonStyleMode.NORMAL);
530e41f4b71Sopenharmony_ci        Button('Textual').controlSize(ControlSize.SMALL).buttonStyle(ButtonStyleMode.TEXTUAL);
531e41f4b71Sopenharmony_ci      }
532e41f4b71Sopenharmony_ci
533e41f4b71Sopenharmony_ci    }.height(400).padding({ left: 35, right: 35, top: 35 })
534e41f4b71Sopenharmony_ci  }
535e41f4b71Sopenharmony_ci}
536e41f4b71Sopenharmony_ci```
537e41f4b71Sopenharmony_ci![image-20230711171138661](figures/buttonstyleandsize.jpeg)
538e41f4b71Sopenharmony_ci
539e41f4b71Sopenharmony_ci### Example 5
540e41f4b71Sopenharmony_ci```ts
541e41f4b71Sopenharmony_ci// xxx.ets
542e41f4b71Sopenharmony_ci@Entry
543e41f4b71Sopenharmony_ci@Component
544e41f4b71Sopenharmony_cistruct ButtonExample {
545e41f4b71Sopenharmony_ci  build() {
546e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
547e41f4b71Sopenharmony_ci      Text('Role is Normal button').fontSize(9).fontColor(0xCCCCCC)
548e41f4b71Sopenharmony_ci      Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
549e41f4b71Sopenharmony_ci        Button('Emphasized', { buttonStyle: ButtonStyleMode.EMPHASIZED, role: ButtonRole.NORMAL });
550e41f4b71Sopenharmony_ci        Button('Normal', { buttonStyle: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL });
551e41f4b71Sopenharmony_ci        Button('Textual', { buttonStyle: ButtonStyleMode.TEXTUAL, role: ButtonRole.NORMAL });
552e41f4b71Sopenharmony_ci      }
553e41f4b71Sopenharmony_ci      Text('Role is Error button').fontSize(9).fontColor(0xCCCCCC)
554e41f4b71Sopenharmony_ci      Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
555e41f4b71Sopenharmony_ci        Button('Emphasized', { buttonStyle: ButtonStyleMode.EMPHASIZED, role: ButtonRole.ERROR});
556e41f4b71Sopenharmony_ci        Button('Normal', { buttonStyle: ButtonStyleMode.NORMAL, role: ButtonRole.ERROR });
557e41f4b71Sopenharmony_ci        Button('Textual', { buttonStyle: ButtonStyleMode.TEXTUAL, role: ButtonRole.ERROR });
558e41f4b71Sopenharmony_ci      }
559e41f4b71Sopenharmony_ci    }.height(200).padding({ left: 35, right: 35, top: 35 })
560e41f4b71Sopenharmony_ci  }
561e41f4b71Sopenharmony_ci}
562e41f4b71Sopenharmony_ci```
563e41f4b71Sopenharmony_ci![buttonrole](figures/buttonrole.jpeg)
564e41f4b71Sopenharmony_ci
565e41f4b71Sopenharmony_ci### Example 6
566e41f4b71Sopenharmony_ciThis example implements a custom button in the shape of a circle. The circle is red when pressed, accompanied by the text "Pressed" in the title. It is black when not pressed, accompanied by the text "Not pressed" in the title.
567e41f4b71Sopenharmony_ci```ts
568e41f4b71Sopenharmony_ciclass MyButtonStyle implements ContentModifier<ButtonConfiguration> {
569e41f4b71Sopenharmony_ci  x: number = 0
570e41f4b71Sopenharmony_ci  y: number = 0
571e41f4b71Sopenharmony_ci  selectedColor:Color = Color.Black
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_ci  constructor(x : number, y: number,ColorType:Color) {
574e41f4b71Sopenharmony_ci    this.x = x
575e41f4b71Sopenharmony_ci    this.y = y
576e41f4b71Sopenharmony_ci    this.selectedColor = ColorType
577e41f4b71Sopenharmony_ci  }
578e41f4b71Sopenharmony_ci  applyContent() : WrappedBuilder<[ButtonConfiguration]>
579e41f4b71Sopenharmony_ci  {
580e41f4b71Sopenharmony_ci    return wrapBuilder(buildButton1)
581e41f4b71Sopenharmony_ci  }
582e41f4b71Sopenharmony_ci}
583e41f4b71Sopenharmony_ci
584e41f4b71Sopenharmony_ci@Builder function buildButton1(config: ButtonConfiguration) {
585e41f4b71Sopenharmony_ci  Column({space:30}) {
586e41f4b71Sopenharmony_ci    Text(config.enabled ? "enabled true" : "enabled false")
587e41f4b71Sopenharmony_ci    Text ('Circle state' + (config.pressed? "(Pressed)": "(Not pressed)"))
588e41f4b71Sopenharmony_ci    Text('X-coordinate of the click point:' + (config.enabled ? (config.contentModifier as MyButtonStyle).x : "0"))
589e41f4b71Sopenharmony_ci    Text('Y-coordinate of the click point:' + (config.enabled ? (config.contentModifier as MyButtonStyle).y : "0"))
590e41f4b71Sopenharmony_ci    Circle({ width: 50, height: 50 })
591e41f4b71Sopenharmony_ci      .fill(config.pressed ? (config.contentModifier as MyButtonStyle).selectedColor : Color.Black)
592e41f4b71Sopenharmony_ci      .gesture(
593e41f4b71Sopenharmony_ci        TapGesture({count:1}).onAction((event: GestureEvent)=>{
594e41f4b71Sopenharmony_ci          config.triggerClick(event.fingerList[0].localX,event.fingerList[0].localY)
595e41f4b71Sopenharmony_ci        })).opacity(config.enabled ? 1 : 0.1)
596e41f4b71Sopenharmony_ci  }
597e41f4b71Sopenharmony_ci}
598e41f4b71Sopenharmony_ci
599e41f4b71Sopenharmony_ci@Entry
600e41f4b71Sopenharmony_ci@Component
601e41f4b71Sopenharmony_cistruct ButtonExample {
602e41f4b71Sopenharmony_ci  @State buttonEnabled: boolean = true;
603e41f4b71Sopenharmony_ci  @State positionX: number = 0
604e41f4b71Sopenharmony_ci  @State positionY: number = 0
605e41f4b71Sopenharmony_ci  @State state : boolean[] = [true,false]
606e41f4b71Sopenharmony_ci  @State index:number = 0
607e41f4b71Sopenharmony_ci  build() {
608e41f4b71Sopenharmony_ci    Column() {
609e41f4b71Sopenharmony_ci      Button('OK')
610e41f4b71Sopenharmony_ci        .contentModifier(new MyButtonStyle(this.positionX,this.positionY,Color.Red))
611e41f4b71Sopenharmony_ci        .onClick((event) => {
612e41f4b71Sopenharmony_ci          console.info('change' + JSON.stringify(event))
613e41f4b71Sopenharmony_ci          this.positionX = event.displayX
614e41f4b71Sopenharmony_ci          this.positionY = event.displayY
615e41f4b71Sopenharmony_ci        }).enabled(this.buttonEnabled)
616e41f4b71Sopenharmony_ci      Row() {
617e41f4b71Sopenharmony_ci        Toggle({ type: ToggleType.Switch, isOn: true }).onChange((value: boolean) => {
618e41f4b71Sopenharmony_ci          if (value) {
619e41f4b71Sopenharmony_ci            this.buttonEnabled = true
620e41f4b71Sopenharmony_ci          } else {
621e41f4b71Sopenharmony_ci            this.buttonEnabled = false
622e41f4b71Sopenharmony_ci          }
623e41f4b71Sopenharmony_ci        }).margin({left:-80})
624e41f4b71Sopenharmony_ci      }
625e41f4b71Sopenharmony_ci    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
626e41f4b71Sopenharmony_ci  }
627e41f4b71Sopenharmony_ci}
628e41f4b71Sopenharmony_ci```
629e41f4b71Sopenharmony_ci![buttonrole](figures/buttonbuilder.gif)
630