鸿蒙:使用bindPopup实现气泡弹窗

前言:

bindPopup可以为组件绑定Popup气泡。

还是老样子,我们参考官方文档进行学习和实践,链接如下:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-universal-attributes-popup#bindpopuphttps://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-universal-attributes-popup#bindpopup

直接上效果图和练习代码:

Index.ets

复制代码
@Entry
@Component
struct Index {
  @State showWarning: boolean = false;

  @Styles
  good(){
    .bindPopup(this.showWarning, {
      message: '气泡弹窗关闭么',
      width: 150,
      messageOptions: {},
      arrowPointPosition: ArrowPointPosition.CENTER,
      placement: Placement.Top,
      showInSubWindow: false,
      keyboardAvoidMode: KeyboardAvoidMode.DEFAULT, // 设置气泡避让软键盘
      primaryButton: {
        value: '确定',
        action: () => {
          this.showWarning = !this.showWarning;
          console.info('confirm Button click');
        },


      },
      // 第二个按钮
      secondaryButton: {
        value: '取消',
        action: () => {
          this.showWarning = !this.showWarning;
          console.info('cancel Button click');
        }
      },
      onStateChange: (e) => {
        console.info(JSON.stringify(e.isVisible))
        if (!e.isVisible) {
          this.showWarning = false;
        }
      }

    })
  }

  build() {
    Column() {
      Button("显示气泡弹窗")
        .width(180)
        .height(40)
        .backgroundColor(Color.Blue)
        .onClick(() => {
          this.showWarning = !this.showWarning;
        })
        .good()
    }
    .backgroundColor(Color.White)
    .width("100%")
    .height("100%")
    .justifyContent(FlexAlign.Center)
  }
}

以上是个人经验分享。

相关推荐
宇宙老魔女3 小时前
APP应用接入华为推送SDK
华为
江湖有缘3 小时前
基于华为openEuler系统安装PDF查看器PdfDing
华为·pdf
鸿蒙小白龙4 小时前
openharmony之充电空闲状态定制开发
harmonyos·鸿蒙·鸿蒙系统·open harmony
万少5 小时前
十行代码 带你极速接入鸿蒙6新特性 - 应用内打分评价
前端·harmonyos
SmartBrain6 小时前
华为MindIE 推理引擎:架构解析
人工智能·华为·架构·推荐算法
LL_Z7 小时前
async/await
harmonyos
竹云科技7 小时前
聚力赋能|竹云受邀出席2025华为全联接大会
华为
科技快报7 小时前
全新尚界H5凭借HUAWEI XMC数字底盘引擎技术,让湿滑路面也“稳”操胜券
华为·harmonyos
猫林老师7 小时前
实战:基于HarmonyOS 5构建分布式聊天通讯应用
分布式·wpf·harmonyos