HarmonyOS 鸿蒙Next中在button按钮上识别双击
HarmonyOS 鸿蒙Next中在button按钮上识别双击
onclick、ontouch无法实现,使用TapGesture实现
https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-basic-gestures-tapgesture
2 回复
在HarmonyOS鸿蒙Next中,可以通过Gesture
模块实现Button按钮的双击识别。使用Gesture
的TapGesture
监听点击事件,设置count
为2来识别双击。示例代码如下:
import { Button, Gesture, TapGesture } from '@ohos.arkui';
let button = new Button();
let tapGesture = new TapGesture({ count: 2 });
tapGesture.onAction(() => {
console.log("Double Tap Detected");
});
button.addGesture(tapGesture);
此代码会在Button上检测到双击时输出日志。
更多关于HarmonyOS 鸿蒙Next中在button按钮上识别双击的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html