【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)we... 透视脚本(WePoKer)wepoker有辅助功能吗(透视)都是是有挂(攻略教程)1、用户打开应用后...
透视黑科技!aapoker辅助... 透视黑科技!aapoker辅助插件工具(透视)脚本(切实存在有挂)aapoker辅助插件工具辅助器中...
透视工具"pokem... 透视工具"pokemmo手机版脚本免费"都是真的有挂(透视)AI教程(有挂揭秘)1)pokemmo手...
透视透视!hhpoker透视方... 透视透视!hhpoker透视方法,好像是真的有挂(透视)透明挂教程(有挂工具)hhpoker透视方法...
透视了解(WEPOKER)we... 透视了解(WEPOKER)wepoker辅助器怎么弄(透视)一直真的有挂(细节方法)1、玩家可以在w...
透视透视!aapoker透视插... 透视透视!aapoker透视插件(透视)插件(竟然有挂)1、起透看视 aapoker透视插件透明视辅...
透视私人局"哈糖大菠... 透视私人局"哈糖大菠萝辅助器"其实真的是有挂(透视)2025新版(有挂细节);亲,关键说明,哈糖大菠...
透视讲解!wepoker私局代... 透视讲解!wepoker私局代打,切实真的是有挂(透视)AI教程(有挂教程)1、wepoker私局代...
透视模拟器(WePoKer)w... 透视模拟器(WePoKer)wepoker是不是有人用挂(透视)总是是有挂(力荐教程);1、许多玩家...
透视科技!aapoker辅助软... 透视科技!aapoker辅助软件合法吗(透视)脚本(竟然是有挂)1、aapoker辅助软件合法吗ai...