harmony 鸿蒙Enable/Disable Control

  • 2025-06-12
  • 浏览 (4)

Enable/Disable Control

You can enable or disable a component to control whether it responds to user interactions. When a component is enabled, it can respond to the following events:

NOTE

The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.

The enabled attribute takes effect only when the component is pressed. It does not work when the component is interacting with the user.

enabled

enabled(value: boolean)

Sets whether the component responds to user interactions.

Widget capability: Since API version 9, this feature is supported in ArkTS widgets.

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

System capability: SystemCapability.ArkUI.ArkUI.Full

Parameters

Name Type Mandatory Description
value boolean Yes Whether the component responds to user interactions, including clicks and touches. The value true means that the component responds to user interactions, and false means the opposite.
Default value: true.

Example

This example demonstrates how to use enable to set whether a button responds to user interactions.

// xxx.ets
@Entry
@Component
struct EnabledExample {
  
  build() {
    Flex({ justifyContent: FlexAlign.SpaceAround }) {
      // The component does not respond to clicks.
      Button('disable').enabled(false).backgroundColor(0x317aff).opacity(0.4)
      Button('enable').backgroundColor(0x317aff)
    }
    .width('100%')
    .padding({ top: 5 })
  }
}

en-us_image_0000001212218428

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArcButton

harmony 鸿蒙ArcSlider

harmony 鸿蒙Chip

harmony 鸿蒙ChipGroup

harmony 鸿蒙ComposeListItem

harmony 鸿蒙ComposeTitleBar

harmony 鸿蒙advanced.Counter

harmony 鸿蒙Dialog Box (Dialog)

harmony 鸿蒙DialogV2

harmony 鸿蒙DownloadFileButton

0  赞