1 Star 0 Fork 0

ScenarioSamples/CustomizDialogWithoutEntry

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
5个月前
5个月前
Loading...
README

不依赖entry的弹窗

介绍

本示例在一个非@Entry的类中创建一个CustomDialogController弹窗,以此来实现不依赖entry的弹窗。

效果预览

图片名称

约束与限制

  1. 本示例仅支持标准系统上运行,支持设备:华为手机。

  2. HarmonyOS系统:HarmonyOS NEXT Release及以上。

  3. DevEco Studio版本:DevEco Studio NEXT Release及以上。

  4. HarmonyOS SDK版本:HarmonyOS NEXT Release SDK及以上。

使用说明

点击请求网络按钮,触发不依赖entry的弹窗。

实现思路

  1. 点击请求网络按钮触发testPromptDialog()方法。
export function testPromptDialog() {
  const that = GlobalContext.getContext().getObject('UIContext') as UIContext;
  if (that) {
    promptAction.openCustomDialog({
      builder: customDialogBuilder.bind(that, '网络请求失败!')
    }).then((dialogId: number) => {
      customDialogId = dialogId;
    })
  }
}
  1. testPromptDialog()方法中触发customDialogBuilder()方法,实现弹窗。
export function customDialogBuilder(content: String) {
  Column() {
    Text(`Tip: ${content} `).fontSize(20).height('30%')
    Text('失败原因:!!!!').fontSize(16).height('30%')
    Row() {
      Button('确认').onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
      Blank().width(50)
      Button('取消').onClick(() => {
        promptAction.closeCustomDialog(customDialogId)
      })
    }
    .margin({top: 30})
  }.height(200).padding(5)
}

工程目录

├──entry/src/main/ets	                 // 代码区
│  ├──entryability
│  │  └──EntryAbility.ets                // 程序入口类
│  └──pages
│     ├──Index.ets                       // 主页面
│     ├──MyShowText.ets                  // 弹窗页面
│     ├──HttpUtils.ets
│     └──GlobalContext.ets
└──entry/src/main/resources              // 资应用资源目录

一份简单的问卷反馈

亲爱的Harmony Next开发者,您好!
为了协助您高效开发,提高鸿蒙场景化示例的质量,希望您在浏览或使用后抽空填写一份简单的问卷,我们将会收集您的宝贵意见进行优化

点击此处填写问卷

空文件

简介

【鸿蒙 Harmony Next 示例 代码】在一个非@Entry的类中创建一个CustomDialogController弹窗 展开 收起
取消

发行版

暂无发行版

贡献者 (2)

全部

近期动态

2个月前推送了新的提交到 master 分支,0b4cd8a...ddb8895
5个月前推送了新的 master 分支
5个月前创建了仓库
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/scenario-samples/customiz-dialog-without-entry.git
git@gitee.com:scenario-samples/customiz-dialog-without-entry.git
scenario-samples
customiz-dialog-without-entry
CustomizDialogWithoutEntry
master

搜索帮助