您好,通过如下的方法获取手机状态栏的高度,返回的高度值较大。日志打印为
statusBar height:126
let widowAvoidArea = this.widowStage.getMainWindowSync().getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM)
let statusBarHeight = widowAvoidArea.topRect.height
麻烦确认下使用上述方法获取状态栏的高度是否正确?返回的高度值为什么偏大?
通过window.getwindowavoidarea可以获取系统规避区域,topRect.height即为状态栏高度,要注意返回单位为px
这个可能是您想获取的数据,关于window详细文档可参考:
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5
状态栏正确高度为:38.86vp,转换为px即126px,您写的代码应该是没有问题.