HarmonyOS CustomDialogController 如何使dialog透明

CustomDialogController 如何使背景透明

HarmonyOS
2024-12-24 16:17:16
1684浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

自定义弹窗想要背景透明需要外部设置参数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 })
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-24 18:37:16


相关问题
HarmonyOS 如何使Dialog覆盖下一个页面
757浏览 • 1回复 待解决
HarmonyOS 自定义Dialog背景色透明问题
1895浏览 • 1回复 待解决
HarmonyOS CustomDialogController如何封装
1068浏览 • 1回复 待解决
HarmonyOS CustomDialogController封装
730浏览 • 1回复 待解决
HarmonyOS CustomDialogController问题
1377浏览 • 1回复 待解决
HarmonyOS UIAbility如何设置透明背景
738浏览 • 1回复 待解决
HarmonyOS使用canvas如何使文字垂直居中
1396浏览 • 1回复 待解决
HarmonyOS 如何设置背景透明
673浏览 • 1回复 待解决
HarmonyOS 如何设置颜色透明
1641浏览 • 1回复 待解决