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

相关内容

热门资讯

第9分钟了解(pokerx)软... 第9分钟了解(pokerx)软件透明挂辅助挂(透视)揭秘教程(2022已更新)(哔哩哔哩);1、完成...
大家学习交流"德州a... 大家学习交流"德州ai辅助器可以收费"详细外挂透明挂辅助黑科技-原生存在有挂(哔哩哔哩);超受欢迎的...
wepoke辅助!竞技联盟破解... wepoke辅助!竞技联盟破解版最新版(透视)2025新版教程(有挂规律)-哔哩哔哩是一款可以让一直...
第5分钟了解!微信小程序雀神挂... 第5分钟了解!微信小程序雀神挂件辅助(辅助挂)详细透视开挂辅助可靠技巧(都是真的是有挂)-哔哩哔哩;...
第一分钟了解(德扑之星软件)外... 第一分钟了解(德扑之星软件)外挂智能ai辅助安装(透视)2025新版(2026已更新)(哔哩哔哩);...
分辨真假"wpk a... 分辨真假"wpk ai辅助在哪买"详细外挂透明挂辅助下载-竟然是真的有挂(哔哩哔哩);wpk ai辅...
wepoke黑科技ai!wpk... wepoke黑科技ai!wpk透视挂是真的(透视)黑科技教程(有挂总结)-哔哩哔哩;超受欢迎的wpk...
3分钟了解!欢乐达人暗堡破解(... 3分钟了解!欢乐达人暗堡破解(辅助挂)详细透视开挂辅助详细教程(确实是真的挂)-哔哩哔哩;3分钟了解...
9分钟了解(Wepoke专用)... 9分钟了解(Wepoke专用)黑科技透明挂辅助黑科技(透视)可靠教程(2020已更新)(哔哩哔哩);...
推荐攻略"we-po... 推荐攻略"we-poker透明挂购买"详细外挂透明挂辅助插件-都是存在有挂(哔哩哔哩);1、点击下载...