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

相关内容

热门资讯

透视计算(wePOke)德扑统... 透视计算(wePOke)德扑统计软件(透视)详细辅助攻略方法;实战中需综合运用上述技巧,并根据牌桌动...
透视挂透视(wepoke)wp... 透视挂透视(wepoke)wpk胜率跟号有关么(透视)详细辅助必赢教程是由北京得wpk胜率跟号有关么...
透视黑科技(wepoke)we... 透视黑科技(wepoke)wepoke挂真的假的(透视)详细辅助介绍教程;小薇(透视辅助)致您一封信...
透视数据(wepoker)we... 透视数据(wepoker)wepoke辅助插件(透视)详细辅助解说技巧;大神普及一款德州ai内幕,确...
透视真的(WePoke)aap... 透视真的(WePoke)aapoker智能ai辅助(透视)详细辅助揭秘教程关于aapoker智能ai...
透视工具(wepoker)wo... 1、透视工具(wepoker)wopoker用ai有用吗(透视)详细辅助黑科技教程。2、wopoke...
透视私人局(wEpoke)德扑... 透视私人局(wEpoke)德扑之星用刷数据吗(透视)详细辅助教你攻略;德扑之星用刷数据吗软件透明挂更...
透视中牌率(wePOKE)we... 透视中牌率(wePOKE)wepoke软件透明挂视频(透视)详细辅助辅助教程1、玩家可以在wepok...
透视辅助(wEpOke)微扑克... 透视辅助(wEpOke)微扑克辅助器是骗人吗(透视)详细辅助新2025版是一款可以让一直输的玩家,快...
透视有挂(WePoke)wpk... 透视有挂(WePoke)wpk长期盈利打法教学(透视)详细辅助透牌教程;亲真的是有正版授权,小编(透...