1# Arc Button (ArcButton) 2 3 4The **ArcButton** component represents an arc button specifically designed for circular screens. It offers various button styles, such as emphasized, normal, and warning, tailored for watch UIs. For details, see [ArcButton](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md). 5 6 7## Creating a Button 8 9To create an **ArcButton** component, use the following: 10 11 ```ts 12ArcButton({ 13 options: new ArcButtonOptions({ 14 label: 'OK', 15 position: ArcButtonPosition.TOP_EDGE, 16 styleMode: ArcButtonStyleMode.EMPHASIZED_LIGHT 17 }) 18}) 19 ``` 20 21- [label](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md#arcbuttonoptions): sets the text displayed on the button. 22 23- [position](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md#arcbuttonoptions): sets the type of the button. 24 25- [styleMode](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md#arcbuttonoptions): sets the style mode of the button. 26 27  28 29## Setting the Button Type 30 31The **ArcButton** component offers two types: top arc button and bottom arc button. Use the [position](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md#arcbuttonoptions) attribute to set the type. 32 33- Lower arc button (default type) 34 35 Set [position](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md#arcbuttonoptions) to **ArcButtonPosition.BOTTOM_EDGE**. 36 37 ```ts 38 ArcButton({ 39 options: new ArcButtonOptions({ 40 label: 'OK', 41 position: ArcButtonPosition.BOTTOM_EDGE, 42 styleMode: ArcButtonStyleMode.EMPHASIZED_LIGHT 43 }) 44 }) 45 ``` 46 47  48 49- Upper arc button 50 51 Set [position](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md#arcbuttonoptions) to **ArcButtonPosition.TOP_EDGE**. 52 53 ```ts 54 ArcButton({ 55 options: new ArcButtonOptions({ 56 label: 'OK', 57 position: ArcButtonPosition.TOP_EDGE, 58 styleMode: ArcButtonStyleMode.EMPHASIZED_LIGHT 59 }) 60 }) 61 ``` 62 63  64 65## Customizing the Style 66 67- Setting the background color 68 69 Use the [backgroundColor](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md#arcbuttonoptions) attribute to set the background color of the button. 70 71 ```ts 72 ArcButton({ 73 options: new ArcButtonOptions({ 74 label: 'OK', 75 styleMode: ArcButtonStyleMode.CUSTOM, 76 backgroundColor: ColorMetrics.resourceColor('#707070') 77 }) 78 }) 79 ``` 80 81  82 83- Setting the font color 84 85 Use the [fontColor](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md#arcbuttonoptions) attribute to set the font color of the button. 86 87 ```ts 88 ArcButton({ 89 options: new ArcButtonOptions({ 90 label: 'OK', 91 styleMode: ArcButtonStyleMode.CUSTOM, 92 backgroundColor: ColorMetrics.resourceColor('#E84026'), 93 fontColor: ColorMetrics.resourceColor('#707070') 94 }) 95 }) 96 ``` 97 98  99 100- Setting the shadow color 101 102 Enable the button shadow using the [shadowEnabled](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md#arcbuttonoptions) attribute and set the shadow color using the [shadowColor](../reference/apis-arkui/arkui-ts/ohos-arkui-advanced-ArcButton.md#arcbuttonoptions) attribute. 103 104 ```ts 105 ArcButton({ 106 options: new ArcButtonOptions({ 107 label: 'OK', 108 shadowEnabled: true, 109 shadowColor: ColorMetrics.resourceColor('#ffec1022') 110 }) 111 }) 112 ``` 113 114  115 116## Adding Events 117 118- Bind the **onClick** event to define custom behavior to be executed when the button is clicked. 119 120 ```ts 121 ArcButton({ 122 options: new ArcButtonOptions({ 123 label: 'OK', 124 onClick: () => { 125 console.info('ArcButton onClick') 126 } 127 }) 128 }) 129 ``` 130 131- Bind the **onTouch** event to define custom behavior to be executed when the button is touched. 132 133 ```ts 134 ArcButton({ 135 options: new ArcButtonOptions({ 136 label: 'OK', 137 onTouch: (event: TouchEvent) => { 138 console.info('ArcButton onTouch') 139 } 140 }) 141 }) 142 ``` 143 144## Example 145 146This example demonstrates a brightness settings screen where a slider displays the current brightness level at 30%. When the reset button is clicked, the brightness value is reset to the default value of 50%. 147 148 ```ts 149import { LengthMetrics, LengthUnit, ArcButton, ArcButtonOptions, ArcButtonStyleMode } from '@kit.ArkUI'; 150 151@Entry 152@ComponentV2 153struct BrightnessPage { 154 @Local brightnessValue: number = 30; 155 private defaultBrightnessValue: number = 50; 156 157 build() { 158 RelativeContainer() { 159 Text('Set brightness') 160 .fontColor(Color.White) 161 .id('id_brightness_set_text') 162 .fontSize(24) 163 .margin({ top: 16 }) 164 .alignRules({ 165 middle: { anchor: '__container__', align: HorizontalAlign.Center } 166 }) 167 168 Text(`${this.brightnessValue} %`) 169 .fontColor(Color.White) 170 .id('id_brightness_min_text') 171 .margin({ left: 16 }) 172 .alignRules({ 173 start: { anchor: '__container__', align: HorizontalAlign.Start }, 174 center: { anchor: '__container__', align: VerticalAlign.Center } 175 }) 176 177 Slider({ 178 value: this.brightnessValue, 179 min: 0, 180 max: 100, 181 style: SliderStyle.InSet 182 }) 183 .blockColor('#191970') 184 .trackColor('#ADD8E6') 185 .selectedColor('#4169E1') 186 .width(150) 187 .id('id_brightness_slider') 188 .margin({ left: 16, right: 16 }) 189 .onChange((value: number, mode: SliderChangeMode) => { 190 this.brightnessValue = value; 191 }) 192 .alignRules({ 193 center: { anchor: 'id_brightness_min_text', align: VerticalAlign.Center }, 194 start: { anchor: 'id_brightness_min_text', align: HorizontalAlign.End } 195 }) 196 197 ArcButton({ 198 options: new ArcButtonOptions({ 199 label: 'Reset', 200 styleMode: ArcButtonStyleMode.EMPHASIZED_LIGHT, 201 fontSize: new LengthMetrics(19, LengthUnit.FP), 202 onClick: () => { 203 this.brightnessValue = this.defaultBrightnessValue; 204 } 205 }) 206 }) 207 .alignRules({ 208 middle: { anchor: '__container__', align: HorizontalAlign.Center }, 209 bottom: { anchor: '__container__', align: VerticalAlign.Bottom } 210 }) 211 } 212 .height('100%') 213 .width('100%') 214 .backgroundColor(Color.Black) 215 } 216} 217 ``` 218 219  220