鸿蒙-弹窗

74 阅读1分钟

弹窗分类为非模态和模态

image.png 非模态:提示一下就消失(文本提示框)

模态: customDialog(不推荐) ,openCustomDialog(非侵入式,不依赖UI组件)

@CustomDialog
struct CustomDialogExample {
  controller: CustomDialogController


  build() {
    Column() {
      Text('我是内容')
        .fontSize(20)
    }.height(60).justifyContent(FlexAlign.Center)
  }
}

@Entry
@Component
struct CustomDialogUser {
  dialogController: CustomDialogController = new CustomDialogController({
    builder: CustomDialogExample(),
  })


  build() {
    Column() {
      Button('click me')
        .onClick(() => {
          this.dialogController.open();
        })
    }.width('100%').margin({ top: 5 })
  }
}

openCustomDialog image.png

无侵入式弹窗 使用 image.png 封装

image.png