harmony 鸿蒙Enable/Disable Control
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:
- Click event
- Touch event
- Drag and drop event
- Key event
- Focus event
- Mouse event
- Axis event
- Hover event
- Accessibility hover event
- Gesture event
- Focus axis event
- Crown event
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 })
}
}
你可能感兴趣的鸿蒙文章
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦