您的位置:首页 > 文旅 > 美景 > 【HarmonyOS开发】弹窗交互(promptAction )

【HarmonyOS开发】弹窗交互(promptAction )

2024/10/5 17:16:35 来源:https://blog.csdn.net/Oneal5354/article/details/140466254  浏览:    关键词:【HarmonyOS开发】弹窗交互(promptAction )

实现效果

  • 点击按钮实现不同方式的弹窗
  • showToast
    在这里插入图片描述
  • showDialog
    在这里插入图片描述
  • showActionMenu
    在这里插入图片描述

代码实现

1.引入’@ohos.promptAction’

import promptAction from '@ohos.promptAction';

2.通过promptAction 实现系统既定的弹窗

import promptAction from '@ohos.promptAction';@Entry
@Component
struct Show_Page {@State message: string = 'Hello World';showToast() {promptAction.showToast({message: "登录成功", //显示内容duration: 2000, //显示持续时间bottom: 400//设置显示的距离底部位置})}showDialog() {promptAction.showDialog({title: "提示",message: "您确定要删除嘛?",buttons: [{text: "取消",color: "#000"},{text: "确定",color: "#000"}]}).then((data) => {console.log(data.index.toString());})}showActionMenu() {promptAction.showActionMenu({title: "选择字体",buttons: [{text: "测试1",color: "#ccc"},{text: "测试2",color: "#ccc"},{text: "测试3",color: "#ccc"},{text: "测试4",color: "#ccc"},{text: "测试5",color: "#ccc"}]}).then((data) => {console.log(data.index.toString());})}build() {Column() {Button() {Text("ShowToast").fontColor(Color.White).fontSize(18)}.width("90%").height(40).margin({ top: 40 }).onClick(() => {this.showToast();})Button() {Text("ShowDialog").fontColor(Color.White).fontSize(18)}.width("90%").height(40).margin({ top: 40 }).onClick(() => {this.showDialog();})Button() {Text("ShowActionMenu").fontColor(Color.White).fontSize(18)}.width("90%").height(40).margin({ top: 40 }).onClick(() => {this.showActionMenu();})}.height('100%').width('100%')}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com