HarmonyOS 页面上创建两个button,只有一个可以收到click事件

@Entry
@Component
struct SplashScreenPage {
  @State pageShowTime: number = CommonConstants.TIME_DEFAULT_VALUE;
  @State intervalID: number = CommonConstants.INTERVAL_ID_DEFAULT;

  build() {
    Column() {
      Stack({ alignContent: Alignment.TopStart }) {
        Image($r('app.media.ic_splash_page_background'))
          .width(CommonConstants.IMAGE_WIDTH)
          .height(CommonConstants.IMAGE_HEIGHT)

        HideButton();
        SkipButton({ secondsCount: (CommonConstants.DELAY_SECONDS - this.pageShowTime) });
      }
      .layoutWeight(CommonConstants.STACK_LAYOUT_WEIGHT)
      .width(CommonConstants.STACK_WIDTH);
    }
    .alignItems(HorizontalAlign.Start)
    .width(CommonConstants.COLUMN_WIDTH)
    .height(CommonConstants.COLUMN_HEIGHT)
  }
}

//其次分别创建两个button

@Component
struct SkipButton {
  @Prop secondsCount: number = 0;

  build() {
    Flex({
      direction: FlexDirection.Row,
      justifyContent: FlexAlign.End
    }) {
      Text($r('app.string.skip', this.secondsCount))
        .onClick(() => {
          console.log("EntryAbility Skip Button is clicked");
        })
    }
  }
}

@Component
struct HideButton {
  build() {
    Flex({
      direction: FlexDirection.Row,
      justifyContent: FlexAlign.Start
    }) {
      Text($r('app.string.hide'))
        .onClick(() => {
          console.log("EntryAbility Hide Button is clicked");
        })
    }
  }
}
  • 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.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
HarmonyOS
2024-12-18 15:51:34
767浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

可以加入属性 .hitTestBehavior(HitTestMode.Transparent),参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-hit-test-behavior-V5

@Component
struct SkipButton {
  @Prop secondsCount: number = 0;

  build() {
    Flex({
      direction: FlexDirection.Row,
      justifyContent: FlexAlign.End
    }) {
      Text($r('app.string.app_name', this.secondsCount))
        .onClick(() => {
          console.log("EntryAbility Skip Button is clicked");
        })
    }
    .hitTestBehavior(HitTestMode.Transparent)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
分享
微博
QQ
微信
回复
2024-12-18 18:07:09
相关问题
HarmonyOS 两个object怎么拼接成一个
1097浏览 • 1回复 待解决
HarmonyOS 怎么把两个PixelMap合成一个
1158浏览 • 2回复 待解决
页面导航如何实现两个页面叠层
2453浏览 • 1回复 待解决
HarmonyOS 一个Button布局的问题
996浏览 • 1回复 待解决
两个重叠的组件如何实现事件透传
1402浏览 • 1回复 待解决
页面导航如何实现A B两个页面叠层
1055浏览 • 1回复 待解决
HarmonyOS llibrary中的两个页面如何跳转
489浏览 • 1回复 待解决