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

相关内容

热门资讯

一分钟快速了解!wpk到底有外... 一分钟快速了解!wpk到底有外挂,wepoke有科技,揭秘教程(有挂猫腻)-哔哩哔哩;亲真的是有正版...
第7分钟了解!pokermas... 第7分钟了解!pokermaster辅助器,hhpoker到底可以透视挂吗(透视)AI教程(有挂细节...
一分钟揭秘!(wpk微扑克)外... 一分钟揭秘!(wpk微扑克)外挂辅助助手!(wpk德州辅助)详细教程(2023已更新)(哔哩哔哩);...
分享一款!德州AI辅助软件,a... 分享一款!德州AI辅助软件,aa poker有挂,2025新版教程(有挂方法)-哔哩哔哩;致您一封信...
第2分钟俱乐部!wpk有透视挂... 第2分钟俱乐部!wpk有透视挂吗,如何下载德普之星辅助软件(透视)新2025教程(有挂详细)1、点击...
推荐攻略!(德扑ai)软件透明... 推荐攻略!(德扑ai)软件透明挂辅助下载!(wepoke真的)2025新版技巧(2022已更新)(哔...
一分钟揭秘!德州ai人工智能,... 一分钟揭秘!德州ai人工智能,wepower俱乐部能胜率,AI教程(有人有挂)-哔哩哔哩;相信小伙伴...
第2分钟知晓!hhpoker软... 第2分钟知晓!hhpoker软件安装包,wepoker辅助脚本(透视)详细教程(果真有挂)1、hhp...
2024版攻略!wpk辅助外挂... 2024版攻略!wpk辅助外挂,aapoker有挂,细节方法(果真有挂)-哔哩哔哩;亲,有的,ai轻...
3分钟晓得!we poker插... 3分钟晓得!we poker插件,xpoker透视辅助(透视)安装教程(有挂技巧)1、3分钟晓得!w...