【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辅助器安装包,透明挂教程(有挂方法);一、智星德州...
透视能赢!智星德州菠萝偷偷看牌... 透视能赢!智星德州菠萝偷偷看牌功能,wpk数据透视,一贯是真的有挂(详细辅助大神讲解)1、不需要AI...
透视有挂!wepoker辅助透... 透视有挂!wepoker辅助透视软件,wepoker免费永久脚本,玩家教你(有挂解密)1、上手简单,...
透视总结!aapoker有挂,... 透视总结!aapoker有挂,微扑克有没有辅助挂,总是真的有挂(详细辅助2025新版教程);进入游戏...
透视app!德普之星透视辅助插... 透视app!德普之星透视辅助插件,aapoker辅助是真的吗,总结教程(有挂细节)德普之星透视辅助插...
透视透视!德州之星插件,德扑牌... 透视透视!德州之星插件,德扑牌型胜率计算,一直是真的有挂(详细辅助玩家教程);1、很好的工具软件,可...
透视肯定!aapoker可以开... 透视肯定!aapoker可以开挂吗,aapoker透视怎么用,必备教程(有挂解密)1、下载好aapo...
透视新版!德州ai辅助软件,微... 透视新版!德州ai辅助软件,微扑克app发牌规律,一贯是真的有挂(详细辅助存在挂教程)1、德州ai辅...
透视黑科技!wpk有脚本吗,h... 透视黑科技!wpk有脚本吗,hhpoker辅助软件,黑科技教程(有挂方法);1)hhpoker辅助软...
透视教学!微扑克有辅助挂,gg... 透视教学!微扑克有辅助挂,gg扑克发牌好假,原来是真的有挂(详细辅助攻略教程)微扑克有辅助挂辅助器中...