当前位置:首页 > 未命名 > 正文内容

鸿蒙next应用全屏设置

dsttl34个月前 (05-22)未命名518

首先,需要判断设备类型,避免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';

扫描二维码推送至手机访问。

版权声明:本文由dsttl3发布,如需转载请注明出处。

本文链接:https://dsttl3.cn/?id=486

分享给朋友: