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

相关内容

热门资讯

黑科技模拟器(德州ai推荐)外... 您好,德州ai推荐这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款...
黑科技辅助!德扑之星的发牌是有... 您好,德扑之星的发牌是有问题这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多...
黑科技辅助!wpk有外挂(透视... 黑科技辅助!wpk有外挂(透视)软件透明挂ai辅助神器(原先真的有挂)-哔哩哔哩;1、不需要AI权限...
黑科技辅助(AAPOKER)外... 黑科技辅助(AAPOKER)外挂透明挂辅助插件(透视)AA德州教程(2022已更新)(哔哩哔哩);亲...
黑科技实锤(Wepoke开挂)... 黑科技实锤(Wepoke开挂)外挂透明挂辅助安装(透视)一贯存在有挂(有挂助手)-哔哩哔哩;Wepo...
黑科技辅助!wepoke用有挂... 黑科技辅助!wepoke用有挂模拟器(透视)本来是真的有挂(确实有挂)-哔哩哔哩;亲,有的,ai轻松...
黑科技辅助(众合扑克)外挂透明... 黑科技辅助(众合扑克)外挂透明挂辅助神器(透视)细节揭秘(2020已更新)(哔哩哔哩);众合扑克最新...
黑科技好友房(fishpoke... 黑科技好友房(fishpoker app)外挂透明挂辅助安装(透视)从前真的有挂(有挂分析)-哔哩哔...
黑科技辅助!云扑克辅助器是真是... 您好,云扑克辅助器是真是假这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩...
黑科技辅助(aapokeR)外... 【福星临门,好运相随】;黑科技辅助(aapokeR)外挂透明挂辅助黑科技(透视)大神讲解(2021已...