鸿蒙next长按事件
import { promptAction } from '@kit.ArkUI';
@Entry
@Component
struct ButtonExample {
@State message: string = 'Button';
build() {
Column() {
Button(this.message)
.fontSize(22)
.fontWeight(FontWeight.Bold)
.gesture(
LongPressGesture({ repeat: true })
.onAction((event?: GestureEvent) => {
if (event) {
promptAction.showToast({
message: '长按了Button',
duration: 2000
})
}
})
)
.onClick(() => {
promptAction.showToast({
message: '点击了Button',
duration: 2000
})
})
}
.height('100%')
.width('100%')
.justifyContent(FlexAlign.Center)
}
}