【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%')   } } 

相关内容

热门资讯

推荐一款!aapoker发牌逻... 推荐一款!aapoker发牌逻辑“讲解开挂透视挂辅助神器”;大家肯定在之前aapoker发牌逻辑或者...
盘点几款!aapoker可以控... 您好,aapoker可以控制牌这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很...
免费测试版!hhpoker软件... 免费测试版!hhpoker软件安装包“总结开挂透视挂辅助软件”是一款可以让一直输的玩家,快速成为一个...
最新通报!wepoker辅助软... 最新通报!wepoker辅助软件价格“2026开挂透视挂辅助插件”是一款可以让一直输的玩家,快速成为...
传递经验!wejoker辅助器... 传递经验!wejoker辅助器可以卖“新版2026开挂透视挂辅助软件”;亲,有的,ai轻松简单,又可...
科技介绍!aapoker脚本“... 科技介绍!aapoker脚本“教你开挂透视挂辅助下载”是一款可以让一直输的玩家,快速成为一个“必胜”...
玩家攻略!pokemmo辅助器... 玩家攻略!pokemmo辅助器“可靠开挂透视挂辅助脚本”;1、让任何用户在无需AI插件第三方神器的情...
推荐一款!德普之星私人局辅助器... 推荐一款!德普之星私人局辅助器“总结开挂透视挂辅助软件”;亲,有的,ai轻松简单,又可以获得无穷的乐...
关于!hhpoker免费透视脚... 关于!hhpoker免费透视脚本“新2026开挂透视挂辅助插件”是一款可以让一直输的玩家,快速成为一...
热门推荐!wepoker可以破... 热门推荐!wepoker可以破解游戏“系统开挂透视挂辅助器”是一款可以让一直输的玩家,快速成为一个“...