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

以上是个人经验分享。

相关推荐
全栈开发圈1 小时前
干货分享|鸿蒙6开发从0到App上线
华为·harmonyos
奔跑的露西ly2 小时前
【HarmonyOS NEXT】ArkUI实现「单格单字符+下划线」手机号/验证码输入框
ui·华为·harmonyos·鸿蒙
木斯佳3 小时前
HarmonyOS实战(人机交互篇):当ToB系统开始“思考”,我们该设计什么样的界面?
华为·人机交互·harmonyos
夜雨声烦丿3 小时前
Flutter 框架跨平台鸿蒙开发 - 中英互译助手 - 完整开发教程
flutter·华为·harmonyos
No Silver Bullet5 小时前
HarmonyOS NEXT开发进阶(二十一):compatibleSdkVersion 和 targetSdkVersion配置项详解
华为·harmonyos
小白阿龙5 小时前
鸿蒙+flutter 跨平台开发——图像编解码与水印嵌入技术实战
flutter·华为·harmonyos·鸿蒙
哈哈你是真的厉害5 小时前
基础入门 React Native 鸿蒙跨平台开发:ActionSheet 动作面板
react native·react.js·harmonyos
夜雨声烦丿6 小时前
Flutter 框架跨平台鸿蒙开发 - 成语词典 - 完整开发教程
flutter·华为·harmonyos
奔跑的露西ly6 小时前
【HarmonyOS NEXT】踩坑记录:00306046 Specification Limit Violation
华为·harmonyos
小白阿龙7 小时前
鸿蒙+flutter 跨平台开发——基于日历视图的生理周期计算逻辑
flutter·华为·harmonyos·鸿蒙