学习笔记(十七):ArkUi-气泡提示 (Popup)
概述:
Popup属性可绑定在组件上显示气泡弹窗提示,设置弹窗内容、交互逻辑和显示状态。主要用于屏幕录制、信息弹出提醒等显示状态。
一、系统气泡,PopupOptions
通过配置primaryButton、secondaryButton来设置带按钮的气泡
1、文本气泡
常用于只展示带有文本的信息提示,不带有任何交互的场景。Popup属性需绑定组件,当bindPopup属性中参数show为true时会弹出气泡提示。
Button('点击显示气泡') .onClick(()=>{ this.showPopup = true }) .bindPopup(this.showPopup, {message:'气泡内容'})
监听气泡显示状态
Button('点击显示气泡') .onClick(()=>{ this.showPopup = true }) .bindPopup(this.showPopup, { message:'气泡内容', onStateChange:(e)=>{ this.showPopup = e.isVisible } })
2、带按钮的提示气泡
通过primaryButton、secondaryButton属性为气泡最多设置两个Button按钮
Button('点击显示气泡') .onClick(()=>{ this.showPopup = true }) .bindPopup(this.showPopup, { message:'气泡内容', onStateChange:(e)=>{ this.showPopup = e.isVisible }, primaryButton:{ value:"确定按钮", action:()=> { console.log('点击了确定') } } ,secondaryButton:{ value:'取消', action:()=>{ console.log('点击了取消') } } })
二、自定义气泡,CustomPopupOptions
使用构建器CustomPopupOptions创建自定义气泡,@Builder中可以放自定义的内容
@Entry @Component struct PopupExample { @State showPopup :boolean = false // 是否显示气泡 // 自定义构建函数组件,自定义气泡的内容元素 @Builder mPopupView(){ Text('自定义气泡内容元素') .padding(20) } build() { Row() { Column() { Button('点击显示气泡') .onClick(()=>{ this.showPopup = true }) .bindPopup(this.showPopup,{ builder: this.mPopupView, // 自定义内容 placement: Placement.Bottom, // 气泡弹出位置 popupColor: Color.Red, // 气泡背景色 onStateChange:(e)=>{ this.showPopup = e.isVisible } }) } .width('100%') } .height('100%') } }
作者:听着music睡
出处:http://www.cnblogs.com/xqxacm/
Android交流群:38197636
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
分类:
鸿蒙学习笔记
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2015-10-31 浅谈RecyclerView(完美替代ListView,GridView)