HarmonyOS CustomDialogController自定义内容深色背景时,底部会有背景漏出?

如题:HarmonyOS CustomDialogController自定义内容深色背景时,底部会有背景漏出?

阅读 478
1 个回答

Controller背景色默认是白色的,自定义弹窗想要背景透明需要外部设置参数 customStyle: true 内部弹窗颜色设置为透明backgroundColor(Color.Transparent) 即可

参考demo

@CustomDialog
@Component
struct CustomDialogExample {
  controller?: CustomDialogController
  build() {
    Column() {
      Text("测试一下弹窗").width(100).height(100).backgroundColor(Color.Orange)
    }.borderRadius(10).backgroundColor(Color.Transparent).height(300)
    // 如果需要使用border属性或cornerRadius属性,请和borderRadius属性一起使用。
  }
}
@Entry
@Component
struct CustomDialogUser {
  @State inputValue: string = 'click me'
  dialogController: CustomDialogController | null = new CustomDialogController({
    builder: CustomDialogExample(),
    cancel: this.exitApp,
    autoCancel: true,
    alignment: DialogAlignment.Bottom,
    offset: { dx: 0, dy: -20 },
    gridCount: 4,
    customStyle: true,
    cornerRadius: 10,
  })

  // 在自定义组件即将析构销毁时将dialogController置空
  aboutToDisappear() {
    this.dialogController = null // 将dialogController置空
  }

  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(this.inputValue)
        .onClick(() => {
          if (this.dialogController != null) {
            this.dialogController.open()
          }
        }).backgroundColor(0x317aff)
    }.width('100%').margin({ top: 5 })
  }
}