禁用控制

2024-01-22 16:10 更新

組件是否可交互,可交互狀態(tài)下響應點擊事件觸摸事件、拖拽事件按鍵事件、焦點事件鼠標事件。

說明

從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標單獨標記該內(nèi)容的起始版本。

屬性

名稱參數(shù)類型描述
enabledboolean

值為true表示組件可交互,響應點擊等操作。

值為false表示組件不可交互,不響應點擊等操作。

默認值:true

從API version 9開始,該接口支持在ArkTS卡片中使用。

示例

  1. // xxx.ets
  2. @Entry
  3. @Component
  4. struct EnabledExample {
  5. build() {
  6. Flex({ justifyContent: FlexAlign.SpaceAround }) {
  7. // 點擊沒有反應
  8. Button('disable').enabled(false).backgroundColor(0x317aff).opacity(0.4)
  9. Button('enable').backgroundColor(0x317aff)
  10. }
  11. .width('100%')
  12. .padding({ top: 5 })
  13. }
  14. }

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號