提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
目前正在学习鸿蒙开发,接下来会发一些相关的文章,大家互相学习
一、创建一个@CustomDialog
@CustomDialog
export struct CustomDialogButton {
controller?: CustomDialogController
confirm: () => void = () => {
}
build() {
Column() {
Text("是否确认退出").fontSize(18).fontWeight(FontWeight.Bold).margin(10)
.width("100%").border({width:{bottom:1}}).textAlign(TextAlign.Center)
.padding({bottom:5}).borderColor("#999")
Flex({justifyContent:FlexAlign.SpaceBetween}){
Button("确认退出",{type:ButtonType.Normal}).backgroundColor("#ff0839ec").borderRadius(5).onClick(()=>{
this.confirm()
})
Button("我不退了",{type:ButtonType.Normal}).backgroundColor("#ffee1111").borderRadius(5).onClick(()=>{
this.controller?.close()
})
}.margin(10)
}
}
}
二、写一个控制器
控制器中的builder中的名字与创建的弹窗名字是一致的
ButtonDialogController: CustomDialogController | null = new CustomDialogController({
builder: CustomDialogButton({
confirm: ()=> {
this.logout()
this.ButtonDialogController?.close()
},
}),
offset:{ dx: 0, dy: 200 }
})
三、调用弹窗
调用的名字是控制器的名字
Button("退出登录",{type:ButtonType.Normal}).borderRadius(5).width("90%").backgroundColor(Color.Red).margin({top:10})
.onClick(()=>{
this.ButtonDialogController?.open()
})