HarmonyOS 鸿蒙Next 使用全局弹窗api问题:promptAction.openCustomDialog
HarmonyOS 鸿蒙Next 使用全局弹窗api问题:promptAction.openCustomDialog
可以通过Navigaiton来实现,您可以试下
index.ets
import { DialogPage } from './DilaogCom';
@Entry
@Component
struct Index {
  @Provide('NavPathStack') pageStack:NavPathStack  = new NavPathStack();
  @Builder PagesMap(name:string,param:string){
    if (name === "Dialog"){
      DialogPage({message:param})
    }
  }
  build() {
    Navigation(this.pageStack){
      Scroll() {
        Column() {
          Button("Push DialogPage").margin(20).width("80%")
            .onClick(()=>{
              this.pageStack.pushPathByName("Dialog","22",true)
            })
        }.width("100%")
      }
      .edgeEffect(EdgeEffect.Spring)
      .friction(0.6)
      .backgroundColor(Color.White)
      .scrollBar(BarState.Off)
      .width('100%')
      .height('100%')
    }.navDestination(this.PagesMap)
  }
}
Dialog.ets
import {Login}  from "./Login"
@Component
export struct  DialogPage{
  message:string  = "23";
  @Consume('NavPathStack') pageStack:NavPathStack;
  build() {
    NavDestination(){
      Login()
    }.backgroundColor('rgba(0,0,0,0.5)')
    .onWillDisappear(()=>{
    }
    ).onWillAppear(()=>{
    })
    .hideTitleBar(true)
    .mode(NavDestinationMode.DIALOG).width("100%").height("100%")
  }
}
Login.ets
@Component
export struct  Login{
  controller: TextInputController = new TextInputController()
  @State text: string = ''
  build() {
    Column(){
      TextInput({ text: this.text, placeholder: 'input your word...', controller: this.controller })
        .placeholderColor(Color.Grey)
        .placeholderFont({ size: 14, weight: 400 })
        .caretColor(Color.Blue)
        .width('95%')
        .height(40)
        .margin(20)
        .fontSize(14)
        .fontColor(Color.Black)
        .inputFilter('[a-z]', (e) => {
          console.log(JSON.stringify(e))
        })
        .onChange((value: string) => {
          this.text = value
        }).backgroundColor(Color.Red)
    }.justifyContent(FlexAlign.End).width("100%").height("100%")
  }
}
由于弹窗存在完全避让输入法行为,弹窗避让软键盘时,与软键盘之间存在16vp的安全间距。目前无法规避
这边建议使用下半拟态弹窗参考文档如下:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-sheet-transition-V5#示例
更多关于HarmonyOS 鸿蒙Next 使用全局弹窗api问题:promptAction.openCustomDialog的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next系统中,使用全局弹窗API promptAction.openCustomDialog 时,需要确保以下几点以正确实现功能:
- 
权限配置:确保在
config.json中已声明使用弹窗的权限,例如ohos.permission.PRESENTATION。 - 
Dialog配置:
openCustomDialog方法需要传入一个CustomDialog对象,确保该对象已正确配置,包括布局文件(XML或JSUI)、内容视图及事件处理。 - 
上下文环境:调用
openCustomDialog时,应传入合适的上下文(Context),通常是当前页面的上下文或应用的全局上下文。 - 
生命周期管理:弹窗的生命周期应与页面或应用的生命周期同步管理,避免在页面销毁后还保留弹窗引用。
 - 
API版本兼容性:检查HarmonyOS版本是否支持你正在使用的API,确保API版本与设备系统版本兼容。
 
示例代码(简化):
import promptAction from '@ohos.multimedia.promptAction';
let dialog = new CustomDialog(this.context, resourceTable.Layout_dialog_layout);
dialog.show();
promptAction.openCustomDialog(dialog);
如果上述步骤正确无误,但问题依旧存在,请检查具体错误信息。如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html
        
      
                  
                  
                  
