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

相关内容

热门资讯

关于透视!hhpoker有作必... 关于透视!hhpoker有作必弊的吗,aapoker免费透视脚本,窍门教程(有挂细节)-哔哩哔哩;1...
玩家必用!卡五星游戏有挂吗,w... 玩家必用!卡五星游戏有挂吗,wepoker网页版透视方法,诀窍教程(今日头条)-哔哩哔哩暗藏猫腻,小...
分享透视!智星德州插件最新版本... 分享透视!智星德州插件最新版本更新内容详解!果然真的有辅助软件(有挂方法)-哔哩哔哩1)智星德州插件...
揭露透视!pokemmo辅助官... 您好,哈糖大菠萝有挂吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩...
详细透视!pokemmo免费脚... 详细透视!pokemmo免费脚本!果然一直总是有辅助脚本(真的有挂)-哔哩哔哩1、完成pokemmo...
盘点几款!微信小程序功夫川码辅... 盘点几款!微信小程序功夫川码辅助,wpk真的有透视嘛,机巧教程(果真有挂)-哔哩哔哩1、游戏颠覆性的...
科普透视!wpk俱乐部辅助器,... 科普透视!wpk俱乐部辅助器,wpk真的有透视嘛,教程书教程(有挂教程)-哔哩哔哩1、超多福利:超高...
玩家必看攻略!中至赣牌圈有没有... 玩家必看攻略!中至赣牌圈有没有辅助,wepoker辅助器免费,资料教程(真实有挂)-哔哩哔哩1、点击...
详情透视!hardrock作必... 详情透视!hardrock作必弊!原来真的是有辅助神器(有挂猫腻)-哔哩哔哩1、玩家可以在hardr...
揭露透视!wepoker有用吗... 揭露透视!wepoker有用吗,wepoker祈福有用吗,课程教程(有挂分析)-哔哩哔哩1、wepo...