#鸿蒙通关秘籍#如何使用bindPopup创建气泡弹窗效果?

HarmonyOS
2024-12-04 15:26:38
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
IoT翠微深处

bindPopup接口能为组件绑定自定义的气泡弹窗。可以设置弹窗内容、交互逻辑及显示状态等。具体步骤如下:

  1. 定义控制显示状态的变量。
  2. 使用@Builder定义弹窗内容。
  3. 在组件上使用bindPopup接口绑定弹窗内容和显示状态。
@Entry
@Component
struct PopupExample {
  @State showPopup: boolean = false;

  @Builder
  MyPopupContent() {
    Column() {
      Row().width(60).height(60).backgroundColor(Color.Red)
      Text('Popup Text')
    }
    .padding(5)
  }

  build() {
    Column() {
      Button('Toggle Popup')
        .onClick(() => {
          this.showPopup = !this.showPopup;
        })
        .bindPopup(this.showPopup, {
          builder: this.MyPopupContent,
          placement: Placement.Top,
          maskColor: 0x33000000,
          popupColor: Color.Gray,
          enableArrow: true,
          onStateChange: (e) => {
            if (!e.isVisible) {
              this.showPopup = false;
            }
          }
        })
    }
  }
}
分享
微博
QQ
微信
回复
2024-12-04 16:19:33
相关问题
HarmonyOS bindPopup自定义气泡问题
59浏览 • 1回复 待解决