HarmonyOS 如何获取底部导航栏高度?

在模拟器内获取底部导航栏高度为0,请问如何获取底部导航栏高度?

阅读 551
1 个回答

获取底部导航条高度,可以参考如下demo:

aboutToAppear(): void {
  window.getLastWindow(getContext(this), (error, topWindow) => {
  if (topWindow) {
    let area = topWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
    let areaBottom = topWindow.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR);
    //注意:返回的是px值,如果要用vp值需要转换
    this.bottomRectHeight = px2vp(areaBottom.bottomRect.height);
    this.statusBarHeight = px2vp(area.topRect.height);
    console.log('this.statusBarHeight' + this.statusBarHeight)
    console.log('this.bottomRectHeight' + this.bottomRectHeight)
  }
});
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进