HarmonyOS 获取手机状态栏高度,返回高度数值偏大?

您好,通过如下的方法获取手机状态栏的高度,返回的高度值较大。日志打印为

statusBar height:126 
let widowAvoidArea = this.widowStage.getMainWindowSync().getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM) 
let  statusBarHeight = widowAvoidArea.topRect.height

麻烦确认下使用上述方法获取状态栏的高度是否正确?返回的高度值为什么偏大?

阅读 630
1 个回答

通过window.getwindowavoidarea可以获取系统规避区域,topRect.height即为状态栏高度,要注意返回单位为px

let statusBarHeight =  px2vp(widowAvoidArea.topRect.height); 

这个可能是您想获取的数据,关于window详细文档可参考:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5

状态栏正确高度为:38.86vp,转换为px即126px,您写的代码应该是没有问题.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进