弧形按钮 (ArcButton)(圆形屏幕推荐使用)
==========================

从API version 18开始支持ArcButton。ArcButton是弧形按钮组件，推荐用于圆形屏幕。为用户提供强调、普通、警告等样式按钮。具体用法请参考[ArcButton](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton)。

#### 创建按钮

ArcButton通过调用以下接口来创建。

ArcButton({
  options: new ArcButtonOptions({
    label: 'OK',
    position: ArcButtonPosition.TOP\_EDGE,
    styleMode: ArcButtonStyleMode.EMPHASIZED\_LIGHT,
  // ···
  })
})

其中，[label](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton#arcbuttonoptions)设置按钮文字，[position](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton#arcbuttonoptions)设置按钮类型，[styleMode](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton#arcbuttonoptions)设置按钮样式。

![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/d2/v3/CTL_j210T8i7F8XzhYLTiQ/zh-cn_image_0000002625187427.png?HW-CC-KV=V1&HW-CC-Date=20260612T073305Z&HW-CC-Expire=86400&HW-CC-Sign=163148777D002615944E9785E9A1528000DB52596C36C2947D23EA44CB01F89F)

#### 设置按钮类型

ArcButton有上弧形按钮和下弧形按钮两种类型。使用[position](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton#arcbuttonoptions)设置按钮类型。

*   下弧形按钮（默认类型）。
    
    通过将[position](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton#arcbuttonoptions)属性设置为ArcButtonPosition.BOTTOM\_EDGE，可以将按钮设置为下弧形按钮。
    
    ArcButton({
      options: new ArcButtonOptions({
        label: 'OK',
        position: ArcButtonPosition.BOTTOM\_EDGE,
        styleMode: ArcButtonStyleMode.EMPHASIZED\_LIGHT,
      // ···
      })
    
    })
    
    ![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/a/v3/RZ5iTvDaRqapq3Kvn4VSPA/zh-cn_image_0000002625107571.png?HW-CC-KV=V1&HW-CC-Date=20260612T073305Z&HW-CC-Expire=86400&HW-CC-Sign=7594DF908C1284CD02560A60A1E8AF5599F6301CFEA322304B110C37A7131133)
    
*   上弧形按钮。
    
    通过将[position](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton#arcbuttonoptions)属性设置为ArcButtonPosition.TOP\_EDGE，可以将按钮设置为上弧形按钮。
    
    ArcButton({
      options: new ArcButtonOptions({
        label: 'OK',
        position: ArcButtonPosition.TOP\_EDGE,
        styleMode: ArcButtonStyleMode.EMPHASIZED\_LIGHT,
      // ···
      })
    })
    
    ![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/fd/v3/sEOWYG9nRsKJXadzWVuVPQ/zh-cn_image_0000002594668054.png?HW-CC-KV=V1&HW-CC-Date=20260612T073305Z&HW-CC-Expire=86400&HW-CC-Sign=EAB3291300A4EB09C167A42CE2DCB2B8D76CAD3E19DEC149A1708CEE8C974ED4)
    

#### 自定义样式

*   设置背景色。
    
    使用[backgroundColor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton#arcbuttonoptions)属性设置按钮的背景色。
    
    ArcButton({
      options: new ArcButtonOptions({
        label: 'OK',
        styleMode: ArcButtonStyleMode.CUSTOM,
        backgroundColor: ColorMetrics.resourceColor('#707070')
      })
    })
    
    ![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/35/v3/JT8jgIHRS4alPkAGT4mvZQ/zh-cn_image_0000002594827982.png?HW-CC-KV=V1&HW-CC-Date=20260612T073305Z&HW-CC-Expire=86400&HW-CC-Sign=0F908AE11514878ED8D58DC114E0F49C90A5D05BC3DD218EDCF1FE98068AD9F9)
    
*   设置文本颜色。
    
    使用[fontColor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton#arcbuttonoptions)属性设置按钮的文本颜色。
    
    ArcButton({
      options: new ArcButtonOptions({
        label: 'OK',
        styleMode: ArcButtonStyleMode.CUSTOM,
        backgroundColor: ColorMetrics.resourceColor('#E84026'),
        fontColor: ColorMetrics.resourceColor('#707070')
      })
    })
    
    ![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/7a/v3/rPncs5UMRlGj7tX4K-_wJg/zh-cn_image_0000002625187429.png?HW-CC-KV=V1&HW-CC-Date=20260612T073305Z&HW-CC-Expire=86400&HW-CC-Sign=BE05B10EBD103FBADED95EB17A5983A4643B719F8B13161EC8105B36053D1296)
    
*   设置阴影颜色。
    
    使用[shadowEnabled](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton#arcbuttonoptions)属性启用按钮阴影，并通过[shadowColor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ohos-arkui-advanced-arcbutton#arcbuttonoptions)属性设置按钮的阴影颜色。
    
    ArcButton({
      options: new ArcButtonOptions({
        label: 'OK',
        shadowEnabled: true,
        shadowColor: ColorMetrics.resourceColor('#ffec1022')
      })
    })
    
    ![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/84/v3/jqReRln6QBmZ5zoTth_0fA/zh-cn_image_0000002625107573.png?HW-CC-KV=V1&HW-CC-Date=20260612T073305Z&HW-CC-Expire=86400&HW-CC-Sign=3E2BD64919EF3DC5D5C34B0FF2F72EE5E45FC725E67640A9C90A62A7B5AE1B36)
    

#### 添加事件

*   绑定onClick事件来响应点击操作后的自定义行为。
    
    ArcButton({
      options: new ArcButtonOptions({
        label: 'OK',
      // ···
        onClick: () => {
          hilog.info(DOMAIN, TAG, 'ArcButton onClick');
        },
      })
    })
    
*   绑定onTouch事件来响应触摸操作后的自定义行为。
    
    ArcButton({
      options: new ArcButtonOptions({
        label: 'OK',
      // ···
        onTouch: (event: TouchEvent) => {
          hilog.info(DOMAIN, TAG, 'ArcButton onTouch');
        }
      })
    
    })
    

#### 场景示例

在亮度设置界面，进度条显示当前亮度为30%。点击重置后，亮度值将被重置为默认的50%。

运行该示例推荐在Wearable设备上以获得最佳显示效果，同时支持在其他设备上运行。若要在Wearable设备上运行，在src/main目录下的工程配置文件[module.json5](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/module-configuration-file)中[deviceTypes标签](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/module-configuration-file#devicetypes标签)内配置wearable。

"module": {
  // ···
  "deviceTypes": \[
    "wearable"
  \],
  // ···
}

import { LengthMetrics, LengthUnit, ArcButton, ArcButtonOptions, ArcButtonStyleMode } from '@kit.ArkUI';

const BRIGHT\_NESS\_VALUE = 30;
const BRIGHT\_NESS\_VALUE\_DEFAULT = 50;

@Entry
@ComponentV2
struct BrightnessPage {
  @Local brightnessValue: number = BRIGHT\_NESS\_VALUE;
  private defaultBrightnessValue: number = BRIGHT\_NESS\_VALUE\_DEFAULT;

  build() {
    RelativeContainer() {
      // 请将$r('app.string.Brightness')替换为实际资源文件，在本示例中该资源文件的value值为"设置亮度"
      Text($r('app.string.Brightness'))
        .fontColor(Color.White)
        .id('id\_brightness\_set\_text')
        .fontSize(24)
        .margin({ top: 16 })
        .alignRules({
          middle: { anchor: '\_\_container\_\_', align: HorizontalAlign.Center }
        })

      Text(\`${this.brightnessValue} %\`)
        .fontColor(Color.White)
        .id('id\_brightness\_min\_text')
        .margin({ left: 16 })
        .alignRules({
          start: { anchor: '\_\_container\_\_', align: HorizontalAlign.Start },
          center: { anchor: '\_\_container\_\_', align: VerticalAlign.Center }
        })

      Slider({
        value: this.brightnessValue,
        min: 0,
        max: 100,
        style: SliderStyle.InSet
      })
        .blockColor('#191970')
        .trackColor('#ADD8E6')
        .selectedColor('#4169E1')
        .width(150)
        .id('id\_brightness\_slider')
        .margin({ left: 16, right: 16 })
        .onChange((value: number, mode: SliderChangeMode) => {
          this.brightnessValue = value;
        })
        .alignRules({
          center: { anchor: 'id\_brightness\_min\_text', align: VerticalAlign.Center },
          start: { anchor: 'id\_brightness\_min\_text', align: HorizontalAlign.End }
        })

      ArcButton({
        options: new ArcButtonOptions({
          // 请将$r('app.string.Reset')替换为实际资源文件，在本示例中该资源文件的value值为"重置"
          label: $r('app.string.Reset'),
          styleMode: ArcButtonStyleMode.EMPHASIZED\_LIGHT,
          fontSize: new LengthMetrics(19, LengthUnit.FP),
          onClick: () => {
            this.brightnessValue = this.defaultBrightnessValue;
          }
        })
      })
        .alignRules({
          middle: { anchor: '\_\_container\_\_', align: HorizontalAlign.Center },
          bottom: { anchor: '\_\_container\_\_', align: VerticalAlign.Bottom }
        })
    }
    .height('100%')
    .width('100%')
    .backgroundColor(Color.Black)
  }
}

![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/62/v3/LepbDEHRSBSIw86pA4rx4g/zh-cn_image_0000002594668056.png?HW-CC-KV=V1&HW-CC-Date=20260612T073305Z&HW-CC-Expire=86400&HW-CC-Sign=B8497C89D202CF5E3589C8DC28ACB5BBD45ADAD3569F542376BE90116977D922)