HarmonyOS 鸿蒙Next导航栏高度获取问题

发布于 1周前 作者 gougou168 最后一次编辑是 5天前 来自 鸿蒙OS

HarmonyOS 鸿蒙Next导航栏高度获取问题

  let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
      // 1. 设置窗口全屏
      let isLayoutFullScreen = true;
      windowClass.setWindowLayoutFullScreen(isLayoutFullScreen);
      let avoidArea = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR);
      let avoidArea2 = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);

      let bottomRectHeight = avoidArea.bottomRect.height;
      let topRectHeight = avoidArea2.topRect.height;

      console.log('rect',bottomRectHeight,topRectHeight)

关于HarmonyOS 鸿蒙Next导航栏高度获取问题的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。

5 回复

状态栏获取的高度是px的

import { window } from '@kit.ArkUI';
import { UIAbility } from '@kit.AbilityKit';

export default class EntryAbility extends UIAbility {
  onWindowStageCreate(windowStage: window.WindowStage): void {
    let windowClass = windowStage.getMainWindowSync()
    let statusBarHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height
    let navigationIndicatorHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height
    AppStorage.setOrCreate('statusBarHeight', statusBarHeight) //保存状态栏高度,单位px
    AppStorage.setOrCreate('navigationIndicatorHeight', navigationIndicatorHeight) //保存底部导航条的高度,单位px
    windowClass.setWindowSystemBarEnable([]); //'status' | 'navigation'
    windowStage.loadContent('pages/Page40');
  }
}

请问,这样获取的是状态栏的高度,也就是显示信号,时间的那一栏的高度。那么状态栏下面的标题栏的高度怎么获取去呢?还是说有固定的值呢

您好,请问您是如何修改状态栏字体颜色呢

EntryAbility.ets

     let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
      let isLayoutFullScreen = true;
      windowClass.setWindowLayoutFullScreen(isLayoutFullScreen)

      let topRectHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height;
      AppStorage.setOrCreate('topRectHeight', topRectHeight + 'px');

      let bottomRectHeight =
        windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height
      AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight + 'px');

感谢感谢,原因确实是因为px和vp单位之间的问题

回到顶部