HarmonyOS CustomDialog打开的页面,如何才能盖在弹窗上面

自定义弹窗打开的页面,如何才能盖在弹窗上面,而弹窗不消失?

HarmonyOS
2024-12-26 14:24:06
465浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

目前无法做到新页面覆盖在弹窗上,因为弹窗与页面不绑定,属于独立的一层。建议使用stack模拟实现dialog的效果。可以通过Stack堆叠布局覆盖在原有的page上面来模拟dialog的效果,stack文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-layout-development-stack-layout-V5

替代方案stack拟态弹窗参考demo:

@Entry
@Component
struct Index {
  @State bottomOpacity: number = 1;
  @State topOpacity: number = 0;
  popShow() {
    console.info("Pop show ...");
    if (this.topOpacity === 1) {
      return;
    }
    console.info("Pop show start ...");
    this.bottomOpacity = 0.6;
    this.topOpacity = 1;
    console.info("Pop show end ...");
  }
  popHide(): void {
    console.info("Pop hide ...");
    if (this.topOpacity === 0) {
      return;
    }
    console.info("Pop hide start ...");
    this.bottomOpacity = 1;
    this.topOpacity = 0;
    console.info("Pop hide end ...");
  }
  build() {
    Stack({ alignContent: Alignment.Bottom }) {
      Column() {
        Text('First child, show in level 1')
          .width('60%')
          .height('20%')
          .align(Alignment.Center)
      }
      .width('100%')
      .height('100%')
      .backgroundColor(0xd2cab3)
      .justifyContent(FlexAlign.Center)
      .opacity(this.bottomOpacity)
      this.popup();
      Button('Click Me')
        .width('40%')
        .height('10%')
        .backgroundColor(Color.Green)
        .zIndex(3)
        .onClick(() => this.popShow())
    }
    .width('100%')
    .height('100%')
    .margin({ top: 5 })
  }
  @Builder popup() {
    if (this.topOpacity === 1) {
      Column() {
        Text('Second child, show in level2')
          .width('70%')
          .height('20%')
          .align(Alignment.Center)
      }
      .width('70%')
      .height('20%')
      .backgroundColor(0xc1cbac)
      .justifyContent(FlexAlign.Center)
      .position({
        x: 50,
        y: 90
      })
      .opacity(this.topOpacity)
      .onClick(() => this.popHide())
    }
  }
}
  • 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.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
分享
微博
QQ
微信
回复
2024-12-26 17:32:24
相关问题
HarmonyOS 自定义弹窗CustomDialog
768浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog 问题
795浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog问题
1365浏览 • 1回复 待解决