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

相关内容

热门资讯

这一现象值得深思!pokemm... 这一现象值得深思!pokemmo辅助器,wepoker手机版辅助(透视)方式教程(原来真的有挂)1、...
出乎意料的是!有哪些免费的wp... 您好,有哪些免费的wpk透视码这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054...
据文件显示!We poker辅... 据文件显示!We poker辅助器下载,哈糖大菠萝破解器(透视)绝活教程(本来真的有挂)1、用户打开...
截至目前!pokemmo手机版... 截至目前!pokemmo手机版脚本免费,hhpoker必备开挂(透视)法门教程(一直是真的挂)暗藏猫...
日前!佛手在线大菠萝技巧,we... 日前!佛手在线大菠萝技巧,wepoker怎么开辅助(透视)步骤教程(切实是有挂)1、让任何用户在无需...
受玩家影响!wpk有那种辅助吗... 受玩家影响!wpk有那种辅助吗,wepoker透视脚本(透视)指南教程(切实真的是有挂)1、上手简单...
一直以来!兴动互娱绥化辅助器挂... 一直以来!兴动互娱绥化辅助器挂,广东雀神挂件去那买(透视)神器-切实真的是有挂1、让任何用户在无需兴...
截至发稿!大当家辅助,兴动休闲... 您好,兴动休闲辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家在...
今年以来!如何购买广东雀神智能... 今年以来!如何购买广东雀神智能插件,战神辅助卡密购买(透视)工具-原来存在有挂1、全新机制【如何购买...
据统计!湖北卡五星技能,九酷互... 您好,湖北卡五星技能这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家...