【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正确养号方法,wepoker透视脚本下载,辅助教程(揭秘有挂);盘点十款!w...
玩家必备教程!情怀游戏辅助器破... 玩家必备教程!情怀游戏辅助器破解版,新天道破解版,透牌教程(有挂规律);《玩家必备教程!情怀游戏辅助...
实测交流!wpk俱乐部辅助器-... 实测交流!wpk俱乐部辅助器-详细开挂透视辅助下载(有开挂猫腻)是一款可以让一直输的玩家,快速成为一...
科普!创思维激k辅助器下载,手... 科普!创思维激k辅助器下载,手机卡五星辅助软件,必备教程(确实有挂)亲,关键说明,创思维激k辅助器下...
玩家必知教程!wepoker游... 玩家必知教程!wepoker游戏安装教程,aapoker怎么设置抽水,可靠技巧(真是有挂)是一款可以...
一分钟带你了解!竹间茶馆辅助,... 您好:四川途游辅助软件这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌...
揭秘真相!约局吧游戏挂-详细开... 您好:约局吧游戏挂这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别...
透视美元局!雀神广东智能插件,... 透视美元局!雀神广东智能插件,四川游戏家园通用辅助,解密教程(有人有挂)1、下载好四川游戏家园通用辅...
揭秘关于!hhpoker真的有... 揭秘关于!hhpoker真的有透视吗,WePOker有没有透视方法,曝光教程(有挂头条);揭秘关于!...
玩家必备攻略!开心泉州辅助免费... 您好,开心泉州辅助免费下载这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩...