HarmonyOS popup自定义自己的背景?

自定义popup,设置使用自己的气泡图片当做背景,但是会有一个白色白底背景。是无法取消这个白色背景吗?

阅读 541
1 个回答

参考下面的Demo

@Entry
@Component
struct BindPopupDemo {

  // 第一步:定义变量控制弹窗显示
  @State customPopup: boolean = false;

  // 第二步:popup构造器定义弹框内容
  @Builder
  customBubbleInstructionBuilder() {
    Stack() {
      Text() {
        Span("2021年12月20日-2022月1日30日每人限购8件 您已购买3件,还可购5件").fontSize(12)
        Span("您已购买3件,还可购5件").fontSize(14)
      }.fontColor(Color.White)
      .maxLines(2).textOverflow({ overflow: TextOverflow.Ellipsis }).ellipsisMode(EllipsisMode.END)
    }.backgroundColor(Color.Green)
    .width(100)
    .padding({
      left: 12,
      right: 12,
      top: 18,
      bottom: 8
    })
  }

  build() {
    Column() {

      Button('click')
        // 第四步:创建点击事件,控制弹窗显隐
        .onClick(() => {
          this.customPopup = !this.customPopup;
        })
        .backgroundColor(0xf56c6c)
          // 第三步:使用bindPopup接口将弹窗内容绑定给元素
        .bindPopup(this.customPopup, {
          builder: this.customBubbleInstructionBuilder,
          placement: Placement.Top,
          maskColor: 0x33000000,
          popupColor: Color.Green,
          enableArrow: true,
          radius: '10vp', // 设置气泡的圆角
          backgroundBlurStyle: BlurStyle.NONE, // 设置箭头颜色
          onStateChange: (e) => {
            if (!e.isVisible) {
              this.customPopup = false;
            }
          }
        })
    }
    .justifyContent(FlexAlign.Center)
    .width('100%')
    .height(437)
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进