HarmonyOS 自定义弹窗选择

在API文档里看到了三种弹框实现,有CustomDialog需要用controller(提取封装比较繁琐暂不考虑),还有两种openCuctomDialog;请问UIcontext里的openCuctomDialog与@ohos.promptAction里的openCustomDialog有什么使用场景上的区别,比如要做全局自定义dialog不依赖于组件甚至在class中调用应该选择哪种?

目前看好像UIcontext里的openCuctomDialog比较合适,但是UIContext里支持的自定义功能并不多,比如弹框背景圆角、宽高、边框等设置,对比CustomDialogOptions。

请问以后自定义dialog的演进是以UIcontext里的openCuctomDialog为准还是以@ohos.promptAction里的openCustomDialog为准。

HarmonyOS
2024-10-10 11:50:55
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
Heiang

自定义全局的dialog演进是以UIcontext里的openCuctomDialog为准,可以不绑定组件,直接使用;但是UIContext里支持的自定义功能并不多, 比如弹框背景圆角、宽高、边框等设置。

可以自定义一个Builder,在里面做弹框背景圆角、宽高、边框等设置,参考示例如下:

import { BusinessError } from '@ohos.base';  
import { ComponentContent } from "@ohos.arkui.node";  
class Params {  
  text: string = ""  
  
  constructor(text: string) {  
    this.text = text;  
  }  
}  
@Builder  
function buildText(params: Params) {  
  Column() {  
    Text(params.text)  
      .fontSize(50)  
      .fontWeight(FontWeight.Bold)  
      .margin({ bottom: 36 })  
  }.backgroundColor('#FFF0F0F0')  
}  
@Entry  
@Component  
struct Index {  
  @State message: string = "hello"  
  build() {  
    Row() {  
      Column() {  
        Button("click me")  
          .onClick(() => {  
            let uiContext = this.getUIContext();  
            let promptAction = uiContext.getPromptAction();  
            let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message));  
            try {  
              promptAction.openCustomDialog(contentNode);  
            } catch (error) {  
              let message = (error as BusinessError).message;  
              let code = (error as BusinessError).code;  
              console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);  
            }  
            ;  
          })  
      }  
      .width('100%')  
      .height('100%')  
    }  
    .height('100%')  
  }  
}
分享
微博
QQ
微信
回复
2024-10-10 18:16:05
相关问题
自定义日期滑动选择弹窗
1458浏览 • 1回复 待解决
自定义弹窗自定义转场动画
2248浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog
1014浏览 • 1回复 待解决
HarmonyOS 自定义图片选择界面
1197浏览 • 1回复 待解决
使用自定义弹窗实现分享弹窗
1643浏览 • 1回复 待解决
HarmonyOS 自定义弹窗 (CustomDialog)问题
1532浏览 • 1回复 待解决
HarmonyOS 自定义弹窗封装问题
1208浏览 • 1回复 待解决
HarmonyOS 如何封装自定义弹窗
1231浏览 • 1回复 待解决
HarmonyOS 唤起自定义弹窗crash
1067浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog问题
1614浏览 • 1回复 待解决
HarmonyOS 自定义弹窗控制问题
1207浏览 • 1回复 待解决
HarmonyOS 自定义弹窗的问题
1930浏览 • 1回复 待解决
HarmonyOS 全局自定义弹窗demo
1439浏览 • 1回复 待解决
HarmonyOS 自定义弹窗关闭问题
1218浏览 • 1回复 待解决
HarmonyOS 自定义弹窗层级问题
1336浏览 • 1回复 待解决
HarmonyOS 使用全局自定义弹窗
1032浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog 问题
1080浏览 • 1回复 待解决
HarmonyOS自定义相册选择页面咨询
1278浏览 • 1回复 待解决
HarmonyOS 自定义弹窗如何更新弹窗的UI
1154浏览 • 1回复 待解决