拿到结果一直是0,代码如下:
window.getLastWindow(getContext(this), (err, windowClass) => {
if (!err.code) {
//保存窗口管理器
this.windowClass = windowClass
//获取状态栏高度
console.log('获取状态栏高度', windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height)
this.statusHeight = px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height)
//获取手机底部规避区域高度
this.bottomAvoidAreaHeight = px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR)
.bottomRect
.height)
windowClass.setWindowLayoutFullScreen(true)
}
})
可以在entryAbility的creat方法中先获取状态栏高度,然后存到全局变量中保存起来以便后面使用。