#鸿蒙通关秘籍#如何在Text组件上实现双击手势?

HarmonyOS
2024-12-04 14:35:15
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
网络小魔头

通过TapGesture,可以实现在Text组件上绑定双击手势。使用TapGesture组件,并将count参数设置为2,定义双击动作。以下是完整示例:

@Entry
@Component
struct Index {
  @State value: string = "";

  build() {
    Column() {
      Text('Click twice').fontSize(28)
        .gesture(
          TapGesture({ count: 2 })
            .onAction((event: GestureEvent|undefined) => {
            if(event){
              this.value = JSON.stringify(event.fingerList[0]);
            }
          }))
      Text(this.value)
    }
    .height(200)
    .width(250)
    .padding(20)
    .border({ width: 3 })
    .margin(30)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
分享
微博
QQ
微信
回复
2024-12-04 16:47:45
相关问题