网站大量收购独家精品文档,联系QQ:2885784924

《HarmonyOS应用开发基础》 课件知识点2-13-2 自定义对话框.pptx

《HarmonyOS应用开发基础》 课件知识点2-13-2 自定义对话框.pptx

  1. 1、本文档共8页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多

自定义对话框

自定义对话框概述使用@CustomDialog装饰器用于装饰自定义弹窗组件,使得弹窗可以动态设置内容及样式。例如:标题、内容、对话框交互按钮等内容和样式都可自定义。如右图所示。

自定义对话框控制器//自定义对话框declare?class?CustomDialogController?{??//自定义对话框的构造方法??constructor(value:?CustomDialogControllerOptions);???open();???????????????//?打开对话框??close();??????????????//?关闭对话框}//自定义对话框常用参数的定义declare?interface?CustomDialogControllerOptions?{??builder:?any;?//对话框内部自定义UI的构造器??cancel?:?()?=?void;?//点击蒙层(对话框外部)的事件回调??autoCancel?:?boolean;?//点击蒙层(对话框外部)是否自动关闭对话框??alignment?:?DialogAlignment;?//对话框在竖直方向上的对齐方式??...}自定义对话框控制器参数与方法说明:

自定义对话框使用自定义对话框组件第一步:使用装饰器@CustomDialog装饰组件。@CustomDialogstruct?DialogExample{}第二步:在自定义对话框中设置参数,可在使用时传入对应参数。@CustomDialogstruct?DialogExample?{??controller:?CustomDialogController??title:?string?=?自定义对话框标题??content:?string?=?对话框内容??confirm:?()?=?void??cancel:?()?=?void}

自定义对话框使用自定义对话框组件第三步:构建自定义对话框显示UI。@CustomDialogstruct?DialogExample?{...??build()?{????Column()?{??????Row()?{????????Text(this.title).fontSize(20).width(100%).textAlign(TextAlign.Center)??????}??????Row()?{????????Text(this.content).fontSize(18)??????}.margin({?top:?10,?bottom:?10?})??????Row({?space:?5?})?{????????Button(取消)??????????.onClick(()?=?{????????????this.controller.close()????????????this.cancel();??????????})??????????.width(50%)????????Button(确认)??????????.onClick(()?=?{????????????this.controller.close()????????????this.confirm()??????????})??????????.width(50%)??????}????}.padding(20)??}}

自定义对话框使用使用自定义对话框组件第一步:创建自定义对话框控制器对象,并选择传入自定义对话框的参数。@Entry@Componentstruct?CustomDialogUser?{??dialogController:?CustomDialogController?=?new?CustomDialogController({????builder:?DialogExample({??????confirm:?this.confirmDialog,??????cancel:?this.cancelDialog?}),????cancel:?this.cancelDialog,????autoCancel:?true//true表示点击对话框外会自动关闭对话框??});confirmDialog(){console.info(Confirmdialog!);}cancelDialog(){console.info(Canceldialog!);}}

自定义对话框使用使用自定义对话框组件第二步:打开对话框。@Entry@Componentstruct?CustomDialogUser?{...??build()?{????Column()?{??????Button(Click?to?open?Dia

您可能关注的文档

文档评论(0)

xiaobao + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档