HarmonyOS 关于CustomDialog显示层级问题

我在A页面弹窗一个CustomDialog,若Dialog未关闭时从A页面跳转到B页面,此时会发现在A页面弹出的Dialog会出现在B页面的层级上方,有什么方式可以让B页面盖住Dialog?

HarmonyOS
2024-12-26 14:57:50
631浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

router跳转:

import router from '@ohos.router';

@CustomDialog
export default struct UserPrivacyDialog {
  controller: CustomDialogController = new CustomDialogController({ builder: '' });
  cancel: Function = () => {
  };
  confirm: Function = () => {
  };
  visible: Visibility = Visibility.None

  build() {
    Column() {
      Button('jump')
        .onClick(() => {
          router.pushUrl({
            url: 'pages/PageTwo'
          })
        }).backgroundColor(0xffffff).fontColor(Color.Red)
    }
    .margin({ top: 22 })
    .justifyContent(FlexAlign.SpaceEvenly)
  }
}

@Entry
@Component
struct Index {
  @State textValue: string = 'Hello World'
  @State visible: Visibility = Visibility.None

  build() {
    Stack() {
      Row() {
        Column() {
          Button('click')
            .onClick(() => {
              if (this.visible == Visibility.Visible) {
                this.visible = Visibility.None
              } else {
                this.visible = Visibility.Visible
              }
            })
            .backgroundColor(0x777474)
            .fontColor(0x000000)
        }
        .width('100%')
      }
      .height('100%')
      .backgroundColor(0x885555)

      Text('')
        .onClick(() => {
          if (this.visible == Visibility.Visible) {
            this.visible = Visibility.None
          } else {
            this.visible = Visibility.Visible
          }
        })
        .width('100%')
        .height('100%')// 透明度可以自己调节一下
        .opacity(0.16)
        .backgroundColor(0x000000)
        .visibility(this.visible)

      Column() {
        GridRow({
          columns: { xs: 1, sm: 4, md: 8, lg: 12 },
          breakpoints: {
            value: ["400vp", "600vp", "800vp"],
            reference: BreakpointsReference.WindowSize
          },
        }) {
          GridCol({
            span: { xs: 1, sm: 2, md: 4, lg: 8 },
            offset: { xs: 0, sm: 1, md: 2, lg: 2 }
          }) {
            Column() {
              Flex({ justifyContent: FlexAlign.SpaceAround }) {
                UserPrivacyDialog();
              }.margin({ bottom: 10 })
            }
            .backgroundColor(0xffffff)
            .visibility(this.visible)
            .clip(true)
            .borderRadius(20)
          }
        }
      }.width('95%') //设置弹窗宽度
    }
  }
}
  • 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.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.

navigation方式跳转:

import promptAction from '@ohos.promptAction';

@Component
export struct Test1 {
  @State message: string = 'Hello World';

  build() {
    NavDestination(){
      Row() {
        Column() {
          Text(this.message)
            .fontSize(50)
            .fontWeight(FontWeight.Bold)
        }
        .width('100%')
      }
      .height('100%')
    }.onBackPressed(()=>{
      promptAction.showToast({message:'123'})
      return false
    })
  }
}

@Entry
@Component
struct Index {
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()
  @State textValue: string = '输入'
  // 显隐控制设置为不占用
  @State visible: Visibility = Visibility.None

  @Builder
  PageMap(name: string) {
    if (name === 'pageOne') {
      Test1()
    }
  }

  build() {
    Navigation(this.pageInfos) {
      Column() {
        Stack() {
          Row() {
            Column() {
              Text('我是第一个页面')
                .fontSize(30)
                .fontWeight(FontWeight.Bold)
              Button('按钮')
                .onClick(() => {
                  console.log("hit me!")
                  if (this.visible == Visibility.Visible) {
                    this.visible = Visibility.None
                  } else {
                    this.visible = Visibility.Visible
                  }
                })
                .backgroundColor(0x777474)
                .fontColor(0x000000)
            }
            .height('100%')
            .width('100%')
            .justifyContent(FlexAlign.Start)
            .alignItems(HorizontalAlign.Center)
          }
          .height('100%')
          .backgroundColor('#FFF')
          Text('')
            .onClick(() => {
              if (this.visible == Visibility.Visible) {
                this.visible = Visibility.None
              } else {
                this.visible = Visibility.Visible
              }
            })
            .width('100%')
            .height('100%')// 透明度可以自己调节一下
            .opacity(0.5)
            .backgroundColor(Color.Black)
            .visibility(this.visible)
          Column() {
            GridRow({
              columns: { xs: 1, sm: 4, md: 8, lg: 12 },
              breakpoints: { value: ["400vp", "600vp", "800vp"],
                reference: BreakpointsReference.WindowSize },
            }) {
              GridCol({
                span: { xs: 1, sm: 2, md: 4, lg: 8 },
                offset: { xs: 0, sm: 1, md: 2, lg: 2 }
              }) {
                Column() {
                  Text('安全隐私').fontSize(20).margin({ top: 10, bottom: 10 })
                  Text('是否跳转到隐私详情页面?').fontSize(16).margin({ bottom: 10 })
                  Flex({ justifyContent: FlexAlign.SpaceAround }) {
                    Button('取消')
                      .onClick(() => {
                        if (this.visible == Visibility.Visible) {
                          this.visible = Visibility.None
                        } else {
                          this.visible = Visibility.Visible
                        }

                      }).backgroundColor(0xffffff).fontColor(Color.Black)
                    Button('确定')
                      .onClick(() => {
                        this.pageInfos.pushPath({ name: 'pageOne' })
                      }).backgroundColor(0xffffff).fontColor(Color.Red)
                  }.margin({ bottom: 10 })
                }
                .backgroundColor(0xffffff)
                .visibility(this.visible)
                .clip(true)
                .borderRadius(20)
              }
            }
          }.width('100%') //设置弹窗宽度
        }
      }.width('100%').margin({ top: 5 })
    }.navDestination(this.PageMap)
  }
}
  • 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.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
分享
微博
QQ
微信
回复
2024-12-26 18:15:24


相关问题
如何控制CustomDialog显示层级
1293浏览 • 1回复 待解决
HarmonyOS CustomDialog显示层级如何控制
598浏览 • 1回复 待解决
HarmonyOS 关于CustomDialog使用
1109浏览 • 1回复 待解决
HarmonyOS CustomDialog显示
502浏览 • 1回复 待解决
HarmonyOS CustomDialog显示顺序
602浏览 • 1回复 待解决
HarmonyOS class中显示CustomDialog
675浏览 • 1回复 待解决
HarmonyOS 关于Abiliaty显示方向的问题
561浏览 • 1回复 待解决
HarmonyOS CustomDialog位置问题
904浏览 • 1回复 待解决
HarmonyOS customdialog使用问题
1552浏览 • 1回复 待解决
HarmonyOS 自定义弹窗层级问题
1007浏览 • 1回复 待解决
HarmonyOS CustomDialog中弹AlertDialog问题
887浏览 • 1回复 待解决
WebView层级问题有知道的吗?
6419浏览 • 1回复 待解决
怎么判断customDialog是否正在显示
909浏览 • 1回复 待解决
HarmonyOS CustomDialog跳转其他页面问题
783浏览 • 1回复 待解决
HarmonyOS 关于组件height百分比显示问题
1117浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog 问题
810浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog问题
1375浏览 • 1回复 待解决
HarmonyOS 自定义CustomDialog 跳转问题
781浏览 • 1回复 待解决