HarmonyOS 如何设置自定义弹框的颜色?

CustomDialogController自定义弹框设置颜色无效,如何设置自定义弹框的颜色?

private loadingDialogController: CustomDialogController | null = new CustomDialogController({
  builder: CustomLoadingDialog(),
  alignment: DialogAlignment.Center,
  cornerRadius: 30,
  backgroundColor: $r("app.color.color11"),
  autoCancel: false,
  gridCount: 2,
  onWillDismiss: () => {
  }
})

backgroundColor这个我设置了没有效果,在CustomLoadingDialog()中设置了父组件的背景颜色,但不能占满整个弹框,怎样设置弹框的颜色呢?

阅读 438
1 个回答

请参考示例:

import promptAction from '@ohos.promptAction'
let customDialogId: number = 0
@Builder
function customDialogBuilder() {
  Column() {
    Text('Custom dialog Message').fontSize(10)
    Row() {
      Button('确认').onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
      Blank().width(50)
      Button('取消').onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
    }
  }.width('100%').height(200).padding(5).backgroundColor("#808080")
}

@Entry
@Component
struct Index {
  @State message: string = '点我'

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            promptAction.openCustomDialog({
              builder: customDialogBuilder.bind(this)
            }).then((dialogId: number) => {
              customDialogId = dialogId
            })
          })
      }
      .width('100%')
    }
    .height('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进