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

相关内容

热门资讯

辅助透视"wepok... 辅助透视"wepoker可以看牌型"推荐开挂作弊辅助插件(竟然存在有挂);一、wepoker可以看牌...
第九分钟透明挂!拱趴大菠萝有什... 第九分钟透明挂!拱趴大菠萝有什挂,能否雀神挂件可以安装(分享透视开挂辅助攻略)1、许多玩家不知道能否...
第2分钟了解“皮皮胡子跑辅助”... 第2分钟了解“皮皮胡子跑辅助”分析开挂辅助插件-果然真的有挂1、皮皮胡子跑辅助透视辅助简单,皮皮胡子...
透视科技"hhpok... 透视科技"hhpoker是正规的"揭幕开挂作弊辅助app(往昔存在有挂)是一款可以让一直输的玩家,快...
七分钟熟悉!wepoker透视... 七分钟熟悉!wepoker透视最简单三个步骤,小闲辅助软件下载(高科技透视开挂辅助神器)1、wepo...
七分钟了解“超级三加一辅助软件... 七分钟了解“超级三加一辅助软件”科普开挂辅助神器-本来真的是有挂1、超级三加一辅助软件系统规律教程、...
透视讲解"hhpok... 透视讲解"hhpoker的辅助是真的"揭幕开挂作弊辅助安装(一贯真的有挂);hhpoker的辅助是真...
第三分钟黑科技!哈糖大菠萝可以... 第三分钟黑科技!哈糖大菠萝可以开挂,新九方科技(透牌透视开挂辅助app)1、很好的工具软件,可以解锁...
十分钟了解“越悦游戏字牌攻略”... 您好,越悦游戏字牌攻略这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩...
透视有挂"pokem... 透视有挂"pokemomo辅助工具"详情开挂作弊辅助脚本(先前存在有挂);相信小伙伴都知道这个pok...