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

以上是个人经验分享。

相关推荐
见山是山-见水是水8 小时前
鸿蒙flutter第三方库适配 - 儿童故事
flutter·华为·harmonyos
2401_839633919 小时前
鸿蒙flutter第三方库适配 - URL处理应用
flutter·华为·harmonyos
不爱吃糖的程序媛9 小时前
鸿蒙三方库适配README.OpenSource文件解读
harmonyos
李李李勃谦11 小时前
Flutter 框架跨平台鸿蒙开发 - 星空日记
flutter·华为·harmonyos
2401_8396339111 小时前
鸿蒙flutter第三方库适配 - 看板应用
flutter·华为·harmonyos
轻口味13 小时前
HarmonyOS 6 自定义人脸识别模型10:基于MindSpore Lite框架的自定义人脸识别功能实现
华为·harmonyos
提子拌饭13313 小时前
生命组学架构下的细胞分化与基因突变生存模拟器:基于鸿蒙Flutter的情景树渲染与状态溢出防御
flutter·华为·架构·开源·harmonyos
HarmonyOS_SDK14 小时前
【FAQ】HarmonyOS SDK 闭源开放能力 —Media Library Kit
harmonyos
SoraLuna16 小时前
「鸿蒙智能体实战记录 14」项目复盘:岁时春信智能体完整实现与能力体系总结
华为·harmonyos
HwJack2016 小时前
HarmonyOS开发中 `onKeyEvent` 事件总线:从“瞎按”到“指哪打哪”的终极掌控
华为·harmonyos