HarmonyOS 子窗口弹出popup问题

使用子窗口弹出popup时,设置showInSubWindow=false,弹窗在子窗口中显示了,目标是弹出在子窗口外部,由于子窗口分配的大小有限,在子窗口中会导致显示不全。

HarmonyOS
2024-12-26 14:50:37
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

窗口内的页面只能显示在窗口内。适配场景demo修改如下:

EntryAbility.ets

import { window } from '@kit.ArkUI';
import UIAbility from '@ohos.app.ability.UIAbility';


export default class EntryAbility extends UIAbility {
  windowClass: window.Window | null = null
  windowStaSge_: window.WindowStage | null = null
  sub_windowClass: window.Window | null = null
  onWindowStageCreate(windowStage: window.WindowStage): void {
    AppStorage.setOrCreate('windowStage', windowStage);
    this.windowStaSge_ = windowStage
    windowStage.getMainWindow((err, data) => {
      if (err.code) {
        return;
      }
      this.windowClass = data;
      this.windowClass.setWindowTouchable(true)
    })

    windowStage.loadContent('pages/Index', (err) => {
      if (err.code) {
        return;
      }
    });
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.

index.ets

import { router, window } from '@kit.ArkUI';

@Entry
@Component
struct Page5 {
  @State message: string = 'Hello World';
  @State windowStage: window.WindowStage = AppStorage.get("windowStage") as window.WindowStage
  onPageShow(): void {}

  onPageHide(): void {
    if (window.findWindow("mySubWindow4").isWindowShowing()) {
      window.findWindow("mySubWindow4").destroyWindow()
    }
  }

  showSubWindow(){
    this.windowStage.createSubWindow("mySubWindow4", (err, windowClass) => {
      if (err.code > 0) {
        console.error("failed to create subWindow Cause:" + err.message)
        return;
      }
      // 设置子窗口加载页
      try {
        windowClass.setUIContent("pages/SubWindow", () => {
          windowClass.setWindowBackgroundColor("#00000000")
        });
        // 设置子窗口左上角坐标
        windowClass.moveWindowTo(0, 200)
        // 设置子窗口大小
        windowClass.resize(vp2px(400), vp2px(400))
        // 展示子窗口
        windowClass.showWindow();
        // 设置子窗口全屏化布局不避让安全区
        windowClass.setWindowLayoutFullScreen(true);
      } catch (err) {
        console.error("failed to create subWindow Cause:" + err)
      }
    })
  }
  build() {
    Column({ space: 5 }) {
      Button('测试虚拟定位功能').onClick(() => {
        this.showSubWindow()
      })

      Button('跳转页面').onClick(() => {
        router.pushUrl({
          url: "pages/TestPage",
          params: {
            name: '我是来自页面Index的数据',
            count: 100
          }
        }, router.RouterMode.Single)
      })

      Button('跳轉頁面 ').onClick(() => {
        router.pushUrl({
          url: "pages/TestPage",
          params: {
            name: '我是来自页面Index的数据',
            count: 100
          }
        }, router.RouterMode.Single)
      })
    }
    .justifyContent(FlexAlign.Center)
    .width('100%')
    .height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
分享
微博
QQ
微信
回复
2024-12-26 18:12:56
相关问题
HarmonyOS 窗口路由切换问题
733浏览 • 1回复 待解决
HarmonyOS 创建窗口后相关问题
500浏览 • 1回复 待解决
HarmonyOS 窗口跳转页面的返回问题
975浏览 • 1回复 待解决
HarmonyOS Popup宽度问题
622浏览 • 1回复 待解决
HarmonyOS 如何拖拽窗口
559浏览 • 1回复 待解决
HarmonyOS 关闭窗口前如何弹出提示?
716浏览 • 1回复 待解决
HarmonyOS Popup气泡支持边框问题
570浏览 • 1回复 待解决
HarmonyOS 窗口是否可手势移动
613浏览 • 1回复 待解决
HarmonyOS 任意位置弹出自定义窗口
515浏览 • 1回复 待解决
如何通过代码关闭窗口
1145浏览 • 1回复 待解决
HarmonyOS 窗口页面返回事件无效
541浏览 • 1回复 待解决
HarmonyOS window.findWindow获取窗口错误
1192浏览 • 1回复 待解决
如何设置窗口的背景颜色?
911浏览 • 1回复 待解决
求告知窗口如何添加动画
881浏览 • 1回复 待解决