鸿蒙_ArkUI组件同时支持双击和单击事件

张开发
2026/4/16 9:13:14 15 分钟阅读

分享文章

鸿蒙_ArkUI组件同时支持双击和单击事件
我们常用的点击事件是onClick想要实现双击需要用TapGesture手势实现那么如果一个组件同时需要支持单击和双击则需要使用GestureGroup我们新建一个页面来测试一下Entry Component struct TestDoubleClick { State message: string 请点击上方文字; build() { Column() { Text(请双击这里) .fontSize(33) .fontWeight(FontWeight.Bold) .margin({ bottom: 20 }) /*.onClick(() { this.message Welcome; })*/ .gesture( TapGesture({ count: 2 }) .onAction(() { this.message Double Click; }) ) Text(单击和双击) .fontSize(33) .fontWeight(FontWeight.Bold) .margin({ bottom: 20 }) .gesture( GestureGroup( //GestureMode.Exclusive, //互斥模式 GestureMode.Parallel, //并行模式推荐 TapGesture({ count: 1 }) .onAction(() { this.message Single Click; }), TapGesture({ count: 2 }) .onAction(() { this.message Double Click; }) )) Text(输出结果 this.message).fontColor(Color.Red) .fontSize(22) } .height(100%) .width(100%) } }运行效果如下

更多文章