《鸿蒙开发-答案之书》自定义弹框

系统的弹框不适用的,很难用。
下面我们来自定义弹框试试

步骤一:

用@CustomDialog注解,标识你是自定义弹框,然后在build里面写你弹框布局
示例代码如下:

@CustomDialog
export struct ChatGoldStandardDialog{
  goldSum:number
  controller: CustomDialogController

  build(){
      Column(){
    
    }
  }
}
步骤二:

在Component组件一开始定义变量那样定义出来
示例代码如下:

 chatGoldStandardDialogController: CustomDialogController|null = new CustomDialogController({
    builder: ChatGoldStandardDialog({
      goldSum:this.chatIntimacyResult.receiveGoldSum,
      
    }),
    customStyle: true,
    autoCancel: false
  })

注意: 记得写customStyle: true,否则它会套默认圆角样式给你的

步骤三:使用
this.chatGoldStandardDialogController?.open()
步骤四:注销
aboutToDisappear(): void {
    this.chatGoldStandardDialogController = null
    }

最好置为null。否则会一直消耗资源,而且它不是随着page关闭。

有鸿蒙开发方面的问题或者需求可以私信我,我每天都看私信的

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐