HarmonyOS 自定义弹框如何半屏包含安全域

半屏底部弹出框,需要包含底部安全域,CustomDialog是否有参数设置,或者其他方案代替

@CustomDialog
struct CustomDialogExample {
  cancel?: () => void
  confirm?: () => void
  controller: CustomDialogController
  build() {
    Column() {
    }.backgroundColor("#FFF").height(200).width('100%')
  }
}

dialogController: CustomDialogController = new CustomDialogController({
  builder: CustomDialogExample({
    cancel: ()=> { this.onCancel() },
    confirm: ()=> { this.onAccept() },
  }),
  width: px2vp(this.windowWidth),
  height: 200,
  customStyle:true
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
HarmonyOS
2024-12-25 08:40:13
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

看下这个demo

@CustomDialog
struct CustomDialogExample {
  @Link textValue: string
  controller?: CustomDialogController
  cancel: () => void = () => {
  }
  confirm: () => void = () => {
  }

  build() {
    Column() {
      Text('Change text').fontSize(20).margin({ top: 10, bottom: 10 })
      TextInput({ placeholder: '', text: this.textValue }).width('90%')
        .onChange((value: string) => {
          this.textValue = value
        })
      Text('Whether to change a text?').fontSize(16).margin({ bottom: 10 })
      Flex({ justifyContent: FlexAlign.SpaceAround }) {
        Button('cancel')
          .onClick(() => {
            if (this.controller != undefined) {
              this.controller.close()
              this.cancel()
            }
          }).backgroundColor(0xffffff).fontColor(Color.Black)
        Button('confirm')
          .onClick(() => {
            if (this.controller != undefined) {
              this.controller.close()
              this.confirm()
            }
          }).backgroundColor(0xffffff).fontColor(Color.Red)
      }.margin({ bottom: 10 })
    }
    .backgroundColor(Color.Orange)
    .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM])
    .height('40%')
    .borderRadius(20)
  }
}
@Entry
@Component
struct CustomDialogUser {
  @State textValue: string = ''
  dialogController: CustomDialogController | null = new CustomDialogController({
    builder: CustomDialogExample({
      cancel: this.onCancel,
      confirm: this.onAccept,
      textValue: $textValue,
    }),
    cancel: this.exitApp,
    autoCancel: true,
    alignment: DialogAlignment.Bottom,
    gridCount: 4,
    customStyle: true,
    backgroundColor: 0xd9ffffff,
  })

  onCancel() {
    console.info('Callback when the first button is clicked')
  }

  onAccept() {
    console.info('Callback when the second button is clicked')
  }

  exitApp() {
    console.info('Click the callback in the blank area')
  }

  build() {
    Column() {
      Button('点击')
        .onClick(() => {
          if (this.dialogController != null) {
            this.dialogController.open()
          }
        }).backgroundColor(0x317aff)
    }.width('100%').height('100%').backgroundColor(Color.Green)
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-25 10:12:13
相关问题
HarmonyOS 自定义封装问题
782浏览 • 1回复 待解决
HarmonyOS 自定义不能全屏
888浏览 • 1回复 待解决
HarmonyOS 自定义组件问题
1245浏览 • 1回复 待解决
HarmonyOS 如何设置自定义的颜色
676浏览 • 1回复 待解决
自定义的状态获取
1566浏览 • 1回复 待解决
如何自定义加上圆角背景
2820浏览 • 1回复 待解决
自定义如何在UIAbility中弹出?
227浏览 • 0回复 待解决
HarmonyOS 背景色如何自定义图片
631浏览 • 1回复 待解决
是否可以自定义权限文字
2515浏览 • 1回复 待解决
HarmonyOS app版本升级需要自定义
887浏览 • 1回复 待解决
HarmonyOS 自定义遮罩透传问题
703浏览 • 1回复 待解决
自定义,遮罩背景颜色无法设置
991浏览 • 1回复 待解决
HarmonyOS 自定义关闭后页面上移
710浏览 • 1回复 待解决
HarmonyOS 自定义导致机测不通过
764浏览 • 1回复 待解决