如何获取状态栏高度?

如何获取状态栏高度

阅读 1.3k
1 个回答

可以在全屏模式下,窗口和状态栏存在重叠,可通过window的AvoidAreaType获取状态栏和窗口重叠区域的属性。

1.通过window的window.getLastWindow获取当前窗口。

2.通过当前窗口实例调用getWindowAvoidArea获取状态栏和窗口重叠区域的属性,此区域的高度即为状态栏的高度。

示例代码

//获取当前窗口 
let windowClass = await window.getLastWindow(getContext(this)); 
//如果没设置全屏就需要设置全屏(非全屏状态下窗口和系统状态栏没有重叠) 
await windowClass.setWindowLayoutFullScreen(true) 
 
let type = window.AvoidAreaType.TYPE_SYSTEM; 
try { 
  let avoidArea = windowClass.getWindowAvoidArea(type); 
  console.log("height: " + avoidArea.topRect.height) 
} catch (exception) { 
  console.error('Failed to obtain the area. Cause:' + JSON.stringify(exception)); 
}

参考链接

获取窗口内容规避的区域

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