鸿蒙_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%) } }运行效果如下
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2501703.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!