【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辅助插件工具,wepoker正确养号方法(详细辅助辅助教程)是一款可以让一直...
透视透视挂!sohoopoke... 透视透视挂!sohoopoker辅助,微信微乐开挂(本来存在有挂)1、进入游戏-大厅左侧-新手福利-...
透视有挂“hhpoker辅助器... 透视有挂“hhpoker辅助器”好像存在有挂(辅助挂)详细辅助2025新版辅助器中分为三种模型:软件...
hhpoker怎么开透视!德普... hhpoker怎么开透视!德普之星透视辅助,aapoker免费透视脚本(详细辅助安装教程)您好,aa...
透视模拟器!aapoker透视... 透视模拟器!aapoker透视脚本,wepoker挂(详细辅助教你攻略)是由北京得aapoker透视...
透视黑科技!德州透视脚本,神兽... 透视黑科技!德州透视脚本,神兽大厅源码(果然真的是有挂);神兽大厅源码是一种具有地方特色的麻将游戏,...
透视透视挂“wpk有脚本吗”一... 透视透视挂“wpk有脚本吗”一贯是有挂(辅助挂)详细辅助安装教程;1、进入到黑科技之后,能看到左侧胜...
红龙poker脚本!pokem... 红龙poker脚本!pokemmo内置修改器,hhpoker免费透视脚本(详细辅助技巧教程)1)hh...
透视插件!智星德州菠萝透视插件... 1、透视插件!智星德州菠萝透视插件工具,wepoker新号好一点吗(详细辅助爆料教程);详细教程。2...
透视有挂!hhpoker开挂教... 透视有挂!hhpoker开挂教程,好友赣南脚本插件(真是真的有挂)1、操作简单,无需注册,只需要使用...