#鸿蒙通关秘籍#如何在2in1设备上实现超出应用界面的弹窗显示?

HarmonyOS
2024-12-10 12:03:52
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
ADSL风绘空

在ArkUI中,通过设置showInSubWindow可以使模态弹窗显示在主窗口之外,以下代码展示了如何实现这一效果:

bash // xxx.ets
@CustomDialog struct CustomDialogExample { controller?: CustomDialogController cancel: () => void = () => { } confirm: () => void = () => { } build() { Column() { Text('可展示在主窗口外的弹窗') .fontSize(30) .height(100) Button('点我关闭弹窗') .onClick(() => { if (this.controller != undefined) { this.controller.close() } }) .margin(20) } } } @Entry @Component struct CustomDialogUser { dialogController: CustomDialogController | null = new CustomDialogController({ builder: CustomDialogExample({ cancel: ()=> { this.onCancel() }, confirm: ()=> { this.onAccept() } }), cancel: this.existApp, autoCancel: true, alignment: DialogAlignment.Center, offset: { dx: 0, dy: -20 }, gridCount: 4, showInSubWindow: true, isModal: true, customStyle: false, cornerRadius: 10, })

aboutToDisappear() { this.dialogController = null }

onCancel() { console.info('Callback when the first button is clicked') }

onAccept() { console.info('Callback when the second button is clicked') }

existApp() { console.info('Click the callback in the blank area') }

build() { Column() { Button('click me') .onClick(() => { if (this.dialogController != null) { this.dialogController.open() } }).backgroundColor(0x317aff) }.width('100%').margin({ top: 5 }) } }

分享
微博
QQ
微信
回复
2024-12-10 13:34:39
相关问题
HarmonyOS 2in1 设备窗口最大化问题
229浏览 • 1回复 待解决
HarmonyOS 2in1怎么禁止最大化
311浏览 • 1回复 待解决