当前位置: 首页 > news >正文

HarmonyOS应用开发学习笔记 arkTS自定义弹窗(CustomDialog)简单使用 arkTS弹出框回调、监听

HarmonyOS应用开发学习笔记 arkTS自定义弹窗(CustomDialog)简单使用

1、@CustomDialog装饰器用于装饰自定义弹框

在这里插入图片描述

1、定义弹出框 @CustomDialog

@CustomDialog
export struct CustomDialogExample {controller: CustomDialogControllerbuild() {Column() {Text("是否退出?").fontSize(30).margin({ top: 60 })Blank()Row() {Text('是').width('50%').height(40).backgroundColor(Color.Blue).fontColor(Color.White).fontSize(18).textAlign(TextAlign.Center)Text('否').width('50%').height(40).backgroundColor(Color.Gray).fontColor(Color.White).fontSize(18).textAlign(TextAlign.Center)}.backgroundColor(Color.Red)}.width('100%').height(200)}
}

2、使用 .open()

  private dialog =new CustomDialogController({ builder: CustomDialogExample() })……Button("拥抱时代").width('80%').margin({ left: 20, top:200, right: 20 }).onClick(() => {this.dialog.open() //淡出淡出狂})

3、弹出框添加回调

在这里插入图片描述
在这里插入图片描述

  • 使用的地方代码
  private dialog = new CustomDialogController({builder: CustomDialogExample({cancel: this.onCancel,confirm: this.onAccept})})//定义onCancel回调方法onCancel() {console.info('Callback when the first button is clicked')}//onAcceptonAccept() {console.info('Callback when the second button is clicked')}
  • 弹出框的代码
@CustomDialog
export struct CustomDialogExample {controller: CustomDialogController //弹出框控制器cancel: () => void //回调方法cancelconfirm: () => void //回调方法confirmbuild() {Column() {Text("是否退出?").fontSize(30).margin({ top: 60 })Blank()Row() {Text('是').width('50%').height(40).backgroundColor(Color.Blue).fontColor(Color.White).fontSize(18).textAlign(TextAlign.Center).onClick(() => {this.controller.close()this.confirm() //调用回调})Text('否').width('50%').height(40).backgroundColor(Color.Gray).fontColor(Color.White).fontSize(18).textAlign(TextAlign.Center).onClick(() => {this.controller.close()this.cancel() //调用回调})}.backgroundColor(Color.Red)}.width('100%').height(200)}
}

在这里插入图片描述

http://www.lryc.cn/news/279745.html

相关文章:

  • RabbitMQ(六)消息的持久化
  • mybatisplus配置
  • node-sass@4.7.2 postinstall: `node scripts/build.js`
  • pyDAL一个python的ORM(9) pyDAL的嵌套查询
  • 融资项目——EasyExcel操作Excel文件
  • OAI openair3-NAS-UE-EMM代码解读(续)
  • SQL-条件查询与聚合函数的使用
  • Qt移植曲线显示
  • 基于springboot生鲜交易系统源码和论文
  • vue中鼠标拖动触发滚动条的移动
  • 1、理解Transformer:革新自然语言处理的模型
  • Acwing847 图中点的层次(bfs)
  • windows11通过虚拟机安装Ubuntu20.04
  • 时序预测 | Matlab实现EEMD-SSA-BiLSTM、EEMD-BiLSTM、SSA-BiLSTM、BiLSTM时序预测对比
  • Android14之解决Pixel手机联网出现感叹号(一百八十)
  • Vmware虚拟机问题解决方案 运行虚拟机系统蓝屏 运行虚拟机时报错VT-x
  • uni-app中轮播图实现大图预览
  • 了解什么是UV纹理?
  • 【蓝桥备赛】wzy的数组Ⅱ——简单莫队问题
  • 学习Qt笔记
  • pymssql 报错误解决办法:20002, severity 9
  • Web缓存代理
  • Rust-模式解构
  • C#基于ScottPlot进行可视化
  • 基于JAVA+ssm开发的在线报名系统设计与实现【附源码】
  • 蓝桥——第 3 场 小白入门赛(A-D)
  • Java项目:06 Springboot的进销存管理系统
  • 数据结构与算法之美学习笔记:47 | 向量空间:如何实现一个简单的音乐推荐系统?
  • 5《Linux》
  • go-carbon v2.3.5 发布,轻量级、语义化、对开发者友好的 golang 时间处理库