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

以上是个人经验分享。

相关推荐
早點睡3901 天前
高级进阶 ReactNative for Harmony项目鸿蒙化三方库集成实战:react-native-image-picker(打开手机相册)
react native·react.js·harmonyos
早點睡3901 天前
基础入门 React Native 鸿蒙跨平台开发:react-native-easy-toast三方库适配
react native·react.js·harmonyos
前端不太难1 天前
在 HarmonyOS 上,游戏状态该怎么“死而复生”
游戏·状态模式·harmonyos
小镇敲码人1 天前
探索华为CANN框架中的Ops-NN仓库
华为·cann·ops-nn
lbb 小魔仙1 天前
【HarmonyOS实战】OpenHarmony + RN:自定义 useValidator 表单验证
华为·harmonyos
仓颉编程语言1 天前
鸿蒙仓颉编程语言挑战赛二等奖作品:TaskGenie 打造基于仓颉语言的智能办公“任务中枢”
华为·鸿蒙·仓颉编程语言
一起养小猫1 天前
Flutter for OpenHarmony 实战:扫雷游戏完整开发指南
flutter·harmonyos
小哥Mark2 天前
Flutter开发鸿蒙年味 + 实用实战应用|绿色烟花:电子烟花 + 手持烟花
flutter·华为·harmonyos
小镇敲码人2 天前
剖析CANN框架中Samples仓库:从示例到实战的AI开发指南
c++·人工智能·python·华为·acl·cann
前端不太难2 天前
HarmonyOS 游戏里,Ability 是如何被重建的
游戏·状态模式·harmonyos