当前位置:网站首页>【Harmony OS】【ARK UI】自定义弹窗
【Harmony OS】【ARK UI】自定义弹窗
2022-08-06 05:27:00 【华为开发者论坛】
自定义弹窗
1.在日常开发当中自定义弹窗会经常用到,之前有遇到想自定义弹窗位置不知该如何去设置的情况(如:相对底部/顶部多少距离)今天就来说一说自定义弹窗的一些属性和用法
官方文档地址:
文档中心

2.代码实现:
@CustomDialog
struct CustomDialogExample {
controller: CustomDialogController
cancel: () => void
confirm: () => void
build() {
Column() {
Text('弹窗标题:卸载软件').width('70%').fontSize(20).margin({ top: 10, bottom: 10 })
Image('comment/bg.jpg').width(80).height(80) //自定义弹窗图片
// Image($r('app.media.icon')).width(80).height(80)
Text('确定要卸载吗?').fontSize(16).margin({ bottom: 10 })
Flex({ justifyContent: FlexAlign.SpaceAround }) {
Button('取消')
.onClick(() => {
this.controller.close()
this.cancel()
}).backgroundColor(0xffffff).fontColor(Color.Black)
Button('确认')
.onClick(() => {
this.controller.close()
this.confirm()
}).backgroundColor(0xffffff).fontColor(Color.Red)
}.margin({ bottom: 10 })
}
}
}
@Entry
@Component
struct CustomDialogUser {
dialogController: CustomDialogController = new CustomDialogController({
builder: CustomDialogExample({ cancel: this.onCancel, confirm: this.onAccept }),
cancel: this.existApp,
autoCancel: true, //点击空白处退出弹窗 false不退出,true退出
alignment: DialogAlignment.Bottom , //垂直底部对齐
offset:{dx:0,dy:-30} //需要注意的是弹窗从底部往上移取负值
})
onCancel() {
console.info('点击取消按钮时的回调')
}
onAccept() {
console.info('单击确认按钮时的回调')
}
existApp() {
console.info('点击空白处的回调')
}
build() {
Column() {
Button('点击按钮触发弹窗')
.onClick(() => {
//open() 打开自定义弹窗
this.dialogController.open()
}).backgroundColor(0x317aff)
}.width('100%').margin({ top: 5 })
}
}3.运行效果:

需要注意的是:
弹窗往上移取负值,向下取正值
欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh
边栏推荐
- 机器视觉——光源选型
- CW008A Copper alloy
- [蒙特卡洛仿真】1
- XCode 下载链接
- Matlab startup Matlab small problem 】 【 a Warning: the Name is nonexistent or not a directory
- [R] language environment configuration Anaconda + R4.1.3 + Pycharm
- Qt 实现窗口大小变化时动画过渡
- QSpinbox 将中文句号 处理 为英文小数点
- KDD 2022 | 中科院计算所提出STABLE:一种无监督高鲁棒性图结构学习框架
- 学习笔记15--驾驶舒适度评价体系
猜你喜欢
随机推荐
C语言和其他高级语言的最大的区别是什么?
【 lambda表达式的使用】
利用R解决常见的数据匹配问题
Notes on ROS files (continuously updated)
R_文字识别(OCR)
el-form表单验证
ZLMediaKit视频推流和播放步骤
【Programming】编程常用英文术语中文对照,及其解释
图像处理(8) : 模板匹配
Pearson相关系数R代码实现
C#和DL-EPI通信
SourceTree 常用技巧
QCompleter的进阶使用
Qt智能指针
新朋老友齐聚首,共话「图形学」未来 | 将门行动派特别直播企划,就在7月6日晚!
libcurl+openssl库交叉编译
SourceTree Common Tips
【R语言】环境配置Anaconda + R4.1.3 + Pycharm
PCL1.12+VTK9.1+QT6编译部署
音视频同步 ffmpeg 推流









