在HarmonyOS NEXT开发中页面上创建两个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");
})
}
}
}
可以加入属性 .hitTestBehavior(HitTestMode.Transparent),参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...