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

相关内容

热门资讯

一分钟教会你!we poker... 一分钟教会你!we poker插件“辅助开挂透视挂辅助下载”;一、we poker插件AI软件牌型概...
第五分钟了解“打大a开挂神器免... 第五分钟了解“打大a开挂神器免费下载”专业开挂辅助神器-确实是真的挂打大a开挂神器免费下载辅助器中分...
4分钟科普!xpoker辅助控... 4分钟科普!xpoker辅助控制,鄱阳翻精辅助下载(黑科技透视开挂辅助神器)1.鄱阳翻精辅助下载 a...
分享开挂内幕!淘宝买wepok... 分享开挂内幕!淘宝买wepoker透视有用“揭秘开挂透视挂辅助插件”;分享开挂内幕!淘宝买wepok...
九分钟了解“烽火互动辅助”分享... 九分钟了解“烽火互动辅助”分享开挂辅助工具-总是存在有挂1、全新机制【烽火互动辅助软件透明挂】2、全...
第三分钟私人局!wpk俱乐部辅... 第三分钟私人局!wpk俱乐部辅助器,逍遥辅助器手机版(AI透视开挂辅助app)1、逍遥辅助器手机版透...
总算了解!pokemmo脚本辅... 总算了解!pokemmo脚本辅助器“辅助开挂透视挂辅助下载”;pokemmo脚本辅助器软件透明挂作为...
第7分钟了解“赣湘互娱挂”必备... 第7分钟了解“赣湘互娱挂”必备开挂辅助挂-一贯有挂1、打开软件启动之后找到中间准星的标志长按。2、然...
9分钟神器!wepoker好友... 9分钟神器!wepoker好友助力码,决战十三水辅助(解说透视开挂辅助神器)小薇(透视辅助)致您一封...
一分钟揭秘!wepokerpl... 一分钟揭秘!wepokerplus透视挂“科技开挂透视挂辅助挂”;人气非常高,ai更新快且高清可以动...