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

相关内容

热门资讯

透视辅助!有哪些免费的wpk辅... 透视辅助!有哪些免费的wpk辅助码(透视)开挂辅助神器(竟然是有挂)-哔哩哔哩该软件可以轻松地帮助玩...
透视规律!如何下载德普之星辅助... 透视规律!如何下载德普之星辅助软件,htx矩阵wepoker辅助,方式教程(本来是真的挂)-哔哩哔哩...
突发!皮皮胡子辅助,掌电竞技辅... 突发!皮皮胡子辅助,掌电竞技辅助器,黑科技教程(原来是有挂)-哔哩哔哩1、这是跨平台的掌电竞技辅助器...
透视新版!hhpoker德州透... 透视新版!hhpoker德州透视,epoker透视底牌,妙计教程(都是存在有挂)-哔哩哔哩1、hhp...
透视代打ai!wepoker透... 透视代打ai!wepoker透视脚本下载(透视)开挂辅助软件(果然真的是有挂)-哔哩哔哩1、点击下载...
相较于以往!越乡游辅助工具,黑... 相较于以往!越乡游辅助工具,黑科技辅助软件免费,力荐教程(原来真的是有挂)-哔哩哔哩1、不需要AI权...
透视真的!wepoker透视方... 透视真的!wepoker透视方法,wepoker辅助真的假的,讲义教程(一直真的是有挂)-哔哩哔哩1...
透视稳赢!wepoker透视脚... 透视稳赢!wepoker透视脚本苹果版(透视)开挂辅助方法(本来是真的挂)-哔哩哔哩1、wepoke...
相较于以往!萍乡滚筒辅助器,丽... 相较于以往!萍乡滚筒辅助器,丽水都莱辅助器,AI教程(好像是真的挂)-哔哩哔哩;1、上手简单,内置详...
透视黑科技!wepoker私人... 您好,wepoker私人局有透视吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【1367043...