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

相关内容

热门资讯

传授透视!hh poker辅助... 传授透视!hh poker辅助器先试用,长春科乐天天踢辅助(透视透视辅助开挂工具);长春科乐天天踢辅...
推荐透视!hhpoker德州挂... 推荐透视!hhpoker德州挂真的有吗,wepoker辅助器是真的吗(附开挂辅助插件);hhpoke...
盘点透视!wepoker私人局... 盘点透视!wepoker私人局可以透视,葫芦娃七子降妖破解版(来一盘开挂辅助插件);1、不需要AI权...
关于透视!poker辅助器免费... 关于透视!poker辅助器免费安装,模拟器打开hhpoker(附开挂辅助平台);超受欢迎的poker...
科技透视!hardrock辅助... 科技透视!hardrock辅助,玉兔追月有挂吗(每日必看推荐辅助开挂下载);1、超多福利:超高返利,...
分析透视!wepoker辅助软... 【福星临门,好运相随】;分析透视!wepoker辅助软件视频,hhpoker为什么一直输(附辅助开挂...
分享透视!安装不了wepoke... 分享透视!安装不了wepoker,手游辅助平台(分享开挂内幕开挂辅助平台);亲,有的,ai轻松简单,...
曝光透视!wpk插件辅助,po... 曝光透视!wpk插件辅助,pokemmo内置修改器(附辅助开挂脚本);一、pokemmo内置修改器A...
正品透视!wepoker底牌透... 正品透视!wepoker底牌透视,新道游游戏辅助器安装包(推荐一款辅助开挂软件);大家肯定在之前新道...
细节透视!xpoker透视辅助... 细节透视!xpoker透视辅助,pokeplus脚本(附开挂辅助下载);AI辅助机器人普及解说快速成...