HarmonyOS 自定义弹框不能全屏?

如题:HarmonyOS 自定义弹框不能全屏?

阅读 571
1 个回答

参考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)
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进