HarmonyOS 自定义dialog open无效

自定义dialog只能在page页面、组件初始化吗?如果不,怎么绑定context?

HarmonyOS
2024-10-10 10:42:09
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

参考此demo:

@CustomDialog  
export struct MyDialog1 {  
  controller1: CustomDialogController  
  title: string = ''  
  build() {  
    Row() {  
      Column({ space: 10 }) {  
        Text(this.title).fontSize(25)  
          .fontColor(Color.Blue)  
        Flex({ justifyContent: FlexAlign.SpaceAround }) {  
          Button('取消')  
            .onClick(() => {  
              this.controller1.close()  
            })  
            .backgroundColor(0xffffff)  
            .fontColor(Color.Black)  
          Button('确认')  
            .onClick(() => {  
              this.controller1.close()  
            })  
            .backgroundColor(0xffffff)  
            .fontColor(Color.Black)  
        }  
        .width('100%')  
      }  
      .width('100%')  
      .backgroundColor(Color.White).height(300)  
    }  
  }  
}  
// main页面  
@Entry  
@Component  
struct Index {  
  @State dialogData: string = ''  
  @State colorTest: Color = Color.Blue  
  dialogController1: CustomDialogController = new CustomDialogController({  
    builder: MyDialog1({  
      title: '弹窗1',  
    }),  
    // 弹窗容器样式是否自定义  
    customStyle: true,  
    offset: { dx: 0, dy: 0 },  
    alignment: DialogAlignment.Bottom  
  })  
  confirm(data: string) {  
    this.dialogData = data  
  }  
  // 在自定义组件即将析构销毁时将dialogController置空  
  aboutToDisappear() {  
  }  
  build() {  
    Row() {  
      Column({ space: 10 }) {  
        Text('这是一个弹窗的测试')  
          .fontSize(25).margin(20).fontColor(0x3399FF)  
        Button('点击打开弹窗')  
          .onClick(() => {  
            this.dialogController1.open()  
          })  
      }.width('100%')  
    }.height('100%').backgroundColor(Color.White)  
  }  
}
  • 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.
分享
微博
QQ
微信
回复
2024-10-10 16:45:46
相关问题
HarmonyOS 自定义Dialog宽度
841浏览 • 1回复 待解决
HarmonyOS 自定义全局dialog
692浏览 • 1回复 待解决
HarmonyOS 自定义全屏dialog
889浏览 • 1回复 待解决
HarmonyOS 自定义dialog相关问题
735浏览 • 1回复 待解决
HarmonyOS 自定义Dialog显示问题
1249浏览 • 1回复 待解决
HarmonyOS 如何封装自定义Dialog
819浏览 • 1回复 待解决
HarmonyOS 用CustomDialog自定义Dialog
1125浏览 • 1回复 待解决
HarmonyOS 自定义Dialog高度问题
756浏览 • 1回复 待解决
HarmonyOS 自定义dialog封装后全局调用
760浏览 • 1回复 待解决
HarmonyOS 自定义Dialog背景色透明问题
1901浏览 • 1回复 待解决
鸿蒙怎么实现自定义布局的Dialog
10073浏览 • 2回复 已解决
HarmonyOS 如何在class中显示自定义dialog
758浏览 • 1回复 待解决
注册的自定义字体在 webview 中无效
3002浏览 • 1回复 待解决
HarmonyOS dialog调用open方法,不显示
1073浏览 • 1回复 待解决