【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怎么拿到好牌,aapoker插件,了解开挂辅助插件(透视有挂细节)>>您好:...
必知教程“德州辅助工具到底怎么... 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理由: 1、软件助手是一款功...
透视辅助!wepoker透视脚... >>您好:拱趴大菠萝万能挂图解确实是有挂的,很多玩家在这款拱趴大菠萝万能挂图解游戏中打牌都会发现很多...
实测揭晓“购买wepoker模... 大家好,今天小编来为大家解答这个问题咨询软件客服可以免费测试直接加微信(136704302)了解详细...
透视辅助!pokemmo手机版... pokemmo手机版透视脚本 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四...
记者爆料“购买的wpk辅助在哪... 您好:这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌特别好,总是好牌...
透视辅助!来玩app 德州 辅... 透视辅助!来玩app 德州 辅助,wepoker轻量版透视方法,分析开挂辅助安装(透视有挂细节)1、...
发现一款“wepoker透视最... 发现一款“wepoker透视最简单三个步骤”开挂(透视)辅助插件(存在挂教程有挂透明挂);无需打开直...
透视辅助!wepoker私人局... 透视辅助!wepoker私人局俱乐部辅助,德州局脚本,正品开挂辅助插件(透视有挂透明挂)您好:wep...
揭秘攻略“wepoker辅助器... 揭秘攻略“wepoker辅助器官方”开挂(透视)辅助下载(教你攻略有挂教学);无需打开直接搜索打开薇...