組件是否可交互,可交互狀態(tài)下響應點擊事件、觸摸事件、拖拽事件、按鍵事件、焦點事件和鼠標事件。
說明
從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標單獨標記該內(nèi)容的起始版本。
屬性
名稱 | 參數(shù)類型 | 描述 |
---|
enabled | boolean | 值為true表示組件可交互,響應點擊等操作。 值為false表示組件不可交互,不響應點擊等操作。 默認值:true 從API version 9開始,該接口支持在ArkTS卡片中使用。 |
示例
- // xxx.ets
- @Entry
- @Component
- struct EnabledExample {
-
- build() {
- Flex({ justifyContent: FlexAlign.SpaceAround }) {
- // 點擊沒有反應
- Button('disable').enabled(false).backgroundColor(0x317aff).opacity(0.4)
- Button('enable').backgroundColor(0x317aff)
- }
- .width('100%')
- .padding({ top: 5 })
- }
- }

更多建議: