HarmonyOS 鸿蒙Next 自定义弹窗显示顶层问题
HarmonyOS 鸿蒙Next 自定义弹窗显示顶层问题
协议弹窗里面有点击事件可以跳转到其他页面,但是这个弹窗会一直显示在新页面上层,如何解决这个问题?
自定义弹窗:
import { LengthMetrics, promptAction } from “@kit.ArkUI” import { Router } from “…/…/common/constants/Router”
@CustomDialog export struct AgreementDialog { controller: CustomDialogController cancel?: () => void confirm?: () => void
build() { Column() { Stack({ alignContent: Alignment.Top }) { Image($r(‘app.media.ic_dialog_top_img’)) .width(‘100%’) .objectFit(ImageFit.Auto) Column() { Text(‘隐私政策’) .margin({ top: 27 }) .fontSize(18) .fontColor($r(‘app.color.color_1a1f1b’)) Scroll() { Text() { Span($r(‘app.string.agreement_content’)) Span($r(‘app.string.agreement_content_one’)).fontColor($r(‘app.color.color_f86e1b’)) .onClick(() => { Router.OpenWebPage(Router.URL_WEB,‘https://www.tingquanxunbao.com’,‘用户服务协议’) // this.controller.close() }) Span($r(‘app.string.agreement_content_two’)) Span($r(‘app.string.agreement_content_three’)).fontColor($r(‘app.color.color_f86e1b’)) .onClick(() => { Router.OpenPage(Router.URL_WEB) this.controller.close() })
Span($r(‘app.string.agreement_content_four’)) Span($r(‘app.string.agreement_content_six’)).fontColor($r(‘app.color.color_f86e1b’)) .onClick(() => { Router.OpenPage(Router.URL_WEB) this.controller.close() }) Span($r(‘app.string.agreement_content_seven’)) Span($r(‘app.string.agreement_content_eight’)).fontColor($r(‘app.color.color_f86e1b’)) .onClick(() => { Router.OpenPage(Router.URL_WEB) this.controller.close() }) Span($r(‘app.string.agreement_content_nine’)) } .fontColor($r(‘app.color.color_636C71’)) .lineSpacing(LengthMetrics.vp(2)) .fontSize(14) }.height(182) .margin({ top: 24, left: 36, right: 36 }) .scrollable(ScrollDirection.Vertical)
Row() { Text(‘不同意’) .width(110) .height(40) .borderRadius(20) .fontColor($r(‘app.color.color_232924’)) .fontSize(14) .fontWeight(FontWeight.Medium) .textAlign(TextAlign.Center) .backgroundColor($r(‘app.color.color_f4f4f4’)) .margin({ right: 5 }) .onClick(() => { if (this.cancel) { this.cancel() } }) Text(‘同意’) .width(110) .fontColor($r(‘app.color.white’)) .fontSize(14) .height(40) .fontWeight(FontWeight.Medium)
.borderRadius(20) .textAlign(TextAlign.Center) .backgroundColor($r(‘app.color.color_232924’)) .margin({ left: 5 }) .onClick(() => { this.controller.close() if (this.confirm) { this.confirm() } }) }.width(‘100%’) .margin({ top: 16, bottom: 23 }) .justifyContent(FlexAlign.Center) } } } } }
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
调用:
dialog = new CustomDialogController({ builder: AgreementDialog({ cancel: this.onCancel, confirm: this.onConfirm, }), onWillDismiss: () => { }, cornerRadius: 15, width: 285, backgroundColor: $r(‘app.color.white’) }) @State time: number = CommonConstants.LAUNCHERPAGETIME @State timeId: number = 0
onPageShow(): void { this.dialog.open() }
说明
当前,ArkUI弹窗均为非页面级弹窗,在页面路由跳转时,如果开发者未调用close方法将其关闭,弹窗将不会自动关闭。若需实现在跳转页面时弹窗同步关闭的场景,建议使用Navigation。具体使用方法,请参考组件导航子页面显示类型的弹窗类型。
更多关于HarmonyOS 鸿蒙Next 自定义弹窗显示顶层问题的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
可以选择不要使用Dialog 而是使用 Window 来处理
针对您提到的HarmonyOS鸿蒙Next自定义弹窗显示顶层问题,这通常涉及到应用窗口权限、系统UI层级管理以及弹窗视图的正确设置。在HarmonyOS系统中,自定义弹窗需要遵循系统对于窗口管理和视图层级的规范。
首先,请确保您的应用已正确申请并获得了显示系统级弹窗所需的权限。这通常包括悬浮窗权限等,具体权限名称可能因系统版本和具体需求而异。
其次,检查您的弹窗视图是否已正确设置为顶层显示。在HarmonyOS中,可以通过设置窗口类型、窗口标志等属性来控制视图的显示层级。确保这些属性已根据系统规范进行设置。
此外,还需要注意系统UI的变化对弹窗显示的影响。例如,在某些情况下,系统UI的更新或变化可能会导致弹窗被遮挡或无法正常显示。针对这种情况,您可以尝试调整弹窗的布局和显示逻辑,以适应系统UI的变化。
如果以上方法均无法解决问题,可能是由于系统版本差异、设备兼容性或其他未知因素导致的。此时,建议您查阅最新的HarmonyOS开发文档,了解系统对于弹窗显示的具体要求和规范。如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html