鸿蒙:使用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)
  }
}

以上是个人经验分享。

相关推荐
金启攻19 小时前
【鸿蒙原生应用实战】第四篇:打包清单——勾选交互、进度计算与实用工具
harmonyos
Swift社区19 小时前
鸿蒙 App 卡顿分析:定位方法 + 优化代码实战
华为·harmonyos
坚果派·白晓明20 小时前
鸿蒙 PC 应用集成 libhv 鸿蒙化三方库 —— AtomCode + Skills 驱动的高效集成实践
c语言·c++·ai编程·harmonyos·atomcode
祭曦念21 小时前
【共创季稿事节】HarmonyOS动态任务列表开发实战
华为·harmonyos
祭曦念21 小时前
【共创季稿事节】鸿蒙原生ArkTS动态列表布局实战_State_ForEach完整指南
华为·harmonyos
不羁的木木1 天前
《HarmonyOS 6.1 新能力实战之智感握姿》第二篇:核心功能——查询与监听握持手状态
华为·harmonyos
风华圆舞1 天前
鸿蒙 + Flutter 下 AI 页面的状态协同设计
人工智能·flutter·harmonyos
互联网散修1 天前
鸿蒙实战:仿小红书“我”的页面——从分层架构到沉浸式交互
交互·harmonyos
aqi001 天前
一文速览 HarmonyOS 6.1.1 推出的十个新特性
android·华为·harmonyos·鸿蒙·harmony
木咺吟1 天前
鸿蒙原生应用实战(三):游戏详情页与交互功能 — 400行ArkTS深度实践
harmonyos