dsttl3.xyz

  • 隐私政策
  • dstt
dsttl3
专注于用户阅读体验的响应式博客主题
  1. 首页
  2. 未分类
  3. 正文

鸿蒙next应用全屏设置

1970-01-01 49点热度 0人点赞

首先,需要判断设备类型,避免PC上无法窗口化运行 这个判断需要在 UIAbility中的onWindowStageCreate()方法内

/**
     * 判断是否是手机设备,如果是手机设备,则设置全屏 (注:2in1设备设置全屏后无法窗口化运行)
     */
    if (deviceInfo.deviceType == 'phone') {
      // 1. 设置全屏
      let windowClass: window.Window = windowStage.getMainWindowSync();
      windowClass.setWindowLayoutFullScreen(true)
        .then(() => {
          console.info('设置全屏成功。');
        })
        .catch((err: BusinessError) => {
          console.error('设置全屏失败。 Cause:' + JSON.stringify(err));
        });
      // 2. 获取导航条区域的高度
      let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR;
      let avoidArea = windowClass.getWindowAvoidArea(type);
      let bottomRectHeight = avoidArea.bottomRect.height;
      AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight);
      console.info(' bottomRectHeight:' + bottomRectHeight);

      // 3. 获取状态栏区域的高度
      let type1 = window.AvoidAreaType.TYPE_SYSTEM;
      let avoidArea1 = windowClass.getWindowAvoidArea(type1);
      let topRectHeight = avoidArea1.topRect.height;
      console.info(' topRectHeight:' + topRectHeight);
      AppStorage.setOrCreate('topRectHeight', topRectHeight);
    }

为避免界面占到导航条和状态栏,需动态获取导航条和状态栏高度,该方法在Page里面获取

  // 底部导航栏高度
  bottomRectHeight: string = AppStorage.get<number>('bottomRectHeight') + 'px';
  // 顶部状态栏高度
  topRectHeight: string = AppStorage.get<number>('topRectHeight') + 'px';
标签: 暂无
最后更新:2025-09-09

dsttl3

https://dsttl3.xyz

点赞
下一篇 >

© 2025 dsttl3.xyz

Theme Kratos Made By Seaton Jiang