参考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.Gray).height('100%') } } } // 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.Top }) confirm(data: string) { this.dialogData = data console.info('ssss') // 获取弹窗输入的信息 } build() { Row() { Column({ space: 10 }) { Text('这是一个弹窗的测试') .fontSize(25).margin(20).fontColor(0x3399FF) Button('点击打开弹窗') .onClick(() => { this.dialogController1.open() }) }.width('100%') }.height('100%').backgroundColor(Color.White) } }
参考demo: