HarmonyOS 有个按钮设置onClick,如果有一层布局覆盖在它上面,这个按钮就响应不了onClick

HarmonyOS 有个按钮设置onClick,如果有一层布局覆盖在它上面,这个按钮就响应不了onClick。

HarmonyOS
2024-10-12 09:25:05
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

设置.hitTestBehavior(HitTestMode.None):

import hilog from '@ohos.hilog';  
@Entry  
@Component  
struct Index {  
  @State message: string = 'Hello World';  
  build() {  
    RelativeContainer() {  
      Text(this.message)  
        .id('HelloWorld')  
        .fontSize(50)  
        .fontWeight(FontWeight.Bold)  
        .alignRules({  
          center: { anchor: '__container__', align: VerticalAlign.Center },  
          middle: { anchor: '__container__', align: HorizontalAlign.Center }  
        })  
        .backgroundColor($r('app.color.test'))  
        .onClick(() => {  
          hilog.debug(0xff, "Text click", 'Text click=====================')  
        })  
      RelativeContainer() {  
        Text('浮层')  
          .id('HelloWorld')  
          .width(100)  
          .height(100)  
          .fontSize(50)  
          .id('fuceng')  
          .backgroundColor($r('app.color.test2'))  
      }.id('djfdshf').hitTestBehavior(HitTestMode.None)  
      .height('100%')  
      .width('100%')  
    }  
    .height('100%')  
    .width('100%')  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
分享
微博
QQ
微信
回复
2024-10-12 17:10:50


相关问题
如何设置通知按钮
1061浏览 • 1回复 待解决
怎么透传onClick事件?
620浏览 • 1回复 待解决