openharmony 鸿蒙 ohos-arkui-advanced-ArcButton

2025-06-12 浏览 (1)

ArcButton

The 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.

NOTE

This component is supported since API version 18. Updates will be marked with a superscript to indicate their earliest API version.

Modules to Import

import {
  ArcButton,
  ArcButtonOptions,
  ArcButtonStatus,
  ArcButtonStyleMode,
  ArcButtonPosition,
}  from '@kit.ArkUI';

Child Components

Not supported

Attributes

The universal attributes are not supported.

Events

Among the universal events, the click event and touch event are supported.

ArcButton

ArcButton({ options: ArcButtonOptions })

Creates an instance of ArcButton with configuration parameters.

Decorator: @Component

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.ArkUI.ArkUI.Circle

Parameters

NameTypeMandatoryDecoratorDescription
optionsArcButtonOptionsYes@RequireText, background color, shadow, and other parameters of the ArcButton component.

ArcButtonOptions

Defines the default or custom style parameters for the ArcButton component.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.ArkUI.ArkUI.Circle

Properties

NameTypeMandatoryDescription
positionArcButtonPositionYesType of the arc button.
Default value: ArcButtonPosition.BOTTOM_EDGE
styleModeArcButtonStyleModeYesStyle mode for the arc button.
Default value: ArcButtonStyleMode.EMPHASIZED_LIGHT
statusArcButtonStatusYesStatus of the arc button.
Default value: ArcButtonStatus.NORMAL
labelResourceStrYesText displayed on the arc button.
backgroundBlurStyleBlurStyleYesBackground blur style of the arc button.
Default value: BlurStyle.NONE
backgroundColorColorMetricsYesBackground color of the arc button.
Default value: Color.Black
shadowColorColorMetricsYesShadow color of the arc button.
Default value: Color.Black
shadowEnabledbooleanYesWhether to enable the shadow for the arc button.
Default value: false
The value true means to enable the shadow, and false means the opposite.
fontSizeLengthMetricsYesFont size of the arc button.
Default value: 19fp
fontColorColorMetricsYesFont color of the arc button.
Default value: Color.White
pressedFontColorColorMetricsYesFont color of the arc button when pressed.
Default value: Color.White
fontStyleFontStyleYesFont style of the arc button.
Default value: FontStyle.Normal
fontFamilystring |ResourceYesFont family of the arc button.
fontMarginLocalizedMarginYesMargin of the arc button text.
Default value: { start: 24vp, top: 10vp,end: 24vp, bottom: 16vp }
onTouchCallback< TouchEvent>NoCallback triggered by touch actions on the arc button.
onClickCallback<ClickEvent) >NoCallback triggered by click actions on the arc button.

constructor

constructor(options: CommonArcButtonOptions)

A constructor used to create an ArcButton component.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.ArkUI.ArkUI.Circle

Parameters

NameTypeMandatoryDescription
optionsCommonArcButtonOptionsYesText, background color, shadow, and other parameters of the ArcButton component.

CommonArcButtonOptions

Defines the default or custom style parameters for the ArcButton component.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.ArkUI.ArkUI.Circle

NameTypeMandatoryDescription
positionArcButtonPositionYesType of the arc button.
Default value: ArcButtonPosition.BOTTOM_EDGE
styleModeArcButtonStyleModeYesStyle mode for the arc button.
Default value: ArcButtonStyleMode.EMPHASIZED_LIGHT
statusArcButtonStatusYesStatus of the arc button.
Default value: ArcButtonStatus.NORMAL
labelResourceStrYesText displayed on the arc button.
backgroundBlurStyleBlurStyleYesBackground blur style of the arc button.
Default value: BlurStyle.NONE
backgroundColorColorMetricsYesBackground color of the arc button.
Default value: Color.Black
shadowColorColorMetricsYesShadow color of the arc button.
Default value: Color.Black
shadowEnabledbooleanYesWhether to enable the shadow for the arc button.
Default value: false
The value true means to enable the shadow, and false means the opposite.
fontSizeLengthMetricsYesFont size of the arc button.
Default value: 19fp
fontColorColorMetricsYesFont color of the arc button.
Default value: Color.White
pressedFontColorColorMetricsYesFont color of the arc button when pressed.
Default value: Color.White
fontStyleFontStyleYesFont style of the arc button.
Default value: FontStyle.Normal
fontFamilystring |ResourceYesFont family of the arc button.
fontMarginLocalizedMarginYesMargin of the arc button text.
Default value: { start: 24vp, top: 10vp,end: 24vp, bottom: 16vp }
onTouchCallback< TouchEvent>NoCallback triggered by touch actions on the arc button.
onClickCallback<ClickEvent) >NoCallback triggered by click actions on the arc button.

ArcButtonPosition

Enumerates the types of arc buttons that can be set for ArcButton.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.ArkUI.ArkUI.Circle

NameValueDescription
TOP_EDGE0Upper arc button located at the top of the circular screen.
BOTTOM_EDGE1Lower arc button located at the bottom of the circular screen.

ArcButtonStyleMode

Enumerates the style modes that can be set for ArcButton.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.ArkUI.ArkUI.Circle

NameValueDescription
EMPHASIZED_LIGHT0Emphasized, light color.
EMPHASIZED_DARK1Emphasized, dark color.
NORMAL_LIGHT2Normal, light color.
NORMAL_DARK3Normal, dark color.
CUSTOM4Custom style.

ArcButtonStatus

Enumerates the states that can be set for ArcButton.

Atomic service API: This API can be used in atomic services since API version 18.

System capability: SystemCapability.ArkUI.ArkUI.Circle

NameValueDescription
NORMAL0Normal state.
PRESSED1Pressed state.
DISABLED2Disabled state.

Example

This example shows the usage of ArcButton.

topOptions defines an upper arc button with the button text "ButtonTop," a font size of 15 fp, and shadow enabled, in the normal state with a light-color emphasized style.

bottomOptions defines a bottom arc button with the button text "ButtonBottom," a font size of 15 fp, shadow enabled, in a light-color emphasized style, with a click event set for the button.

// xxx.ets
import {
  ColorMetrics,
  LengthMetrics,
  LengthUnit,
  ArcButton,
  ArcButtonOptions,
  ArcButtonStatus,
  ArcButtonStyleMode,
  ArcButtonTypeMode,
}  from '@kit.ArkUI';

@Entry
@ComponentV2
struct Index {
  @Local topOptions: ArcButtonOptions = new ArcButtonOptions({})
  @Local bottomOptions: ArcButtonOptions = new ArcButtonOptions({})

  aboutToAppear() {
    this.topOptions = new ArcButtonOptions({
      label: 'ButtonTop',
      status: ArcButtonStatus.NORMAL,
      position: ArcButtonPosition.TOP_EDGE,
      styleMode: ArcButtonStyleMode.EMPHASIZED_LIGHT,
      fontSize: new LengthMetrics(15, LengthUnit.FP),
      shadowEnabled: true
    })

    this.bottomOptions = new ArcButtonOptions({
      label: 'ButtonBottom',
      styleMode: ArcButtonStyleMode.EMPHASIZED_LIGHT,
      fontSize: new LengthMetrics(15, LengthUnit.FP),
      shadowEnabled: true,
      onClick: () => {
        console.info('click from ArcButton.')
      }
    })
  }

  build() {
    Stack() {
      Stack() {
        Circle({ width: 233, height: 233 })
          .strokeWidth(0.1)
          .fill(Color.White)

        Column() {
          ArcButton({ options: this.topOptions })
          Blank()
          ArcButton({ options: this.bottomOptions })

        }.width('100%')
        .height('100%')
      }.width(233)
      .height(233)
    }.width('100%')
    .height('100%')
    .alignContent(Alignment.Center)
    .backgroundColor(Color.Gray)
  }
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArcSlider

harmony 鸿蒙Chip

harmony 鸿蒙ChipGroup

harmony 鸿蒙ComposeListItem

harmony 鸿蒙ComposeTitleBar

harmony 鸿蒙advanced.Counter

harmony 鸿蒙Dialog Box (Dialog)

harmony 鸿蒙DialogV2

harmony 鸿蒙DownloadFileButton

harmony 鸿蒙EditableTitleBar

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/9dXzmD