【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智... 第九分钟了解!wepoker智能辅助插件(透视)外挂透视辅助第九(其实是有挂);1、下载好wepok...
一分钟了解!川南休闲辅助,闲逸... 一分钟了解!川南休闲辅助,闲逸辅助插件(详细辅助普及教程);是一款可以让一直输的玩家,快速成为一个“...
第2分钟了解!拱趴大菠萝万能辅... 第2分钟了解!拱趴大菠萝万能辅助器(透视)外挂透视辅助第2(其实有挂);1.拱趴大菠萝万能辅助器 a...
专业讨论!赣牌圈小程序辅助器,... 专业讨论!赣牌圈小程序辅助器,河洛杠次怎么提高胜率(详细辅助扑克教程)(1)专业讨论!赣牌圈小程序辅...
一分钟了解!wepoker底牌... 一分钟了解!wepoker底牌透视脚本(透视)外挂透视辅助一(竟然是真的有挂);1、wepoker底...
一分钟教你!中至余干有挂吗,广... 一分钟教你!中至余干有挂吗,广西老友辅助(详细辅助攻略教程)中至余干有挂吗辅助器中分为三种模型:中至...
教程攻略!爱来510k辅助器,... 教程攻略!爱来510k辅助器,福建兄弟十三水辅助工具(详细辅助可靠技巧)您好,福建兄弟十三水辅助工具...
第4分钟了解!哈糖大菠萝破解器... 第4分钟了解!哈糖大菠萝破解器(透视)外挂透视辅助第4(都是是有挂)1、哈糖大菠萝破解器ai辅助优化...
十分钟了解!wepoker高级... 十分钟了解!wepoker高级辅助(透视)外挂透视辅助十(确实有挂)1、wepoker高级辅助系统规...
实测揭晓!陕麻圈脚本辅助,闲逸... 实测揭晓!陕麻圈脚本辅助,闲逸辅助app下载(详细辅助透明挂教程)是一款可以让一直输的玩家,快速成为...