【HarmonyOS开发】弹窗交互(promptAction )
创始人
2025-01-09 10:37:43
0次

实现效果

  • 点击按钮实现不同方式的弹窗
  • 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%')   } } 

相关内容

热门资讯

实测分享,wepoker透视挂... wepoker透视挂是真的吗AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载对应游戏...
揭秘几款,新版德扑之星透视,德... 揭秘几款,新版德扑之星透视,德州扑克多功能ai辅助秘籍教程主打本地运行的 AI 黑科技工具迎来新版本...
透明挂教程,德扑之星破解app... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成德扑之星破解app下载解析、 AI ...
科普常识,wepoker是不是... 科普常识,wepoker是不是有透视软件,德州扑克多功能ai开挂法子工具是一款可以让一直输的玩家,快...
玩家必看分享,wpk辅助kaq... 很多人使用云端 AI 时,都担心wpk辅助kaq665、内部资料上传带来隐私风险。这款本地运行的 A...
攻略方法,微扑克辅助工具免费版... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...
总算了解!,runit德州透视... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成runit德州透视软件辅助挂解析、 ...
今日公布,德州辅助软件,WPK... 今日公布,德州辅助软件,WPK多功能ai辅助器方针教程主打赛后复盘的 AI 游戏攻略黑科技走红,对局...
让我来分享经验,wepoker... 您好:wepoker辅助器教程这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
攻略讲解,德扑之星开挂作弊,A... 攻略讲解,德扑之星开挂作弊,AApoker多功能ai辅助器手筋脚本是一款可以让一直输的玩家,快速成为...