HarmonyOS 如何获取屏幕顶部和底部安全区域的高度

HarmonyOS 如何获取屏幕顶部和底部安全区域的高度

HarmonyOS
2024-08-10 12:12:05
2115浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

尝试下 导入 import window from ‘@ohos.window’;、

参考代码:

onPageShow(): void { window.getLastWindow(getContext(this), (err, win) => { 
  //获取避让类型为系统导航条 
  let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; 
  let avoidArea = win.getWindowAvoidArea(type); 
  let bottomRectHeight = px2vp(avoidArea.bottomRect.height); 
  let topRectRectHeight = px2vp(avoidArea.topRect.height); 
 
  console.log("bottomRectHeight :::: " + bottomRectHeight); 
  console.log("topRectRectHeight :::: " + topRectRectHeight); 
}) 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

参考文档: 获取当前应用内最上层的子窗口,若无应用子窗口,则返回应用主窗口,使用callback异步回调。https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-window-0000001820880785#ZH-CN_TOPIC_0000001811317218__windowgetlastwindow9

窗口内容规避区域。https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-window-0000001820880785#ZH-CN_TOPIC_0000001811317218__avoidarea7

分享
微博
QQ
微信
回复
2024-08-10 17:46:35
相关问题
HarmonyOS 如何获取手机安全区域高度
799浏览 • 1回复 待解决
HarmonyOS 页面底部流出安全区域
875浏览 • 1回复 待解决
关于屏幕安全区域问题咨询
1092浏览 • 1回复 待解决
HarmonyOS 安全区域失效
765浏览 • 1回复 待解决
HarmonyOS 安全区域问题
991浏览 • 1回复 待解决
HarmonyOS 安全区域出错
802浏览 • 1回复 待解决
HarmonyOS WebView安全区域问题
613浏览 • 1回复 待解决
HarmonyOS scroll安全区域问题
856浏览 • 1回复 待解决
HarmonyOS 设置安全区域不生效
849浏览 • 1回复 待解决
HarmonyOS 视频组件无法扩展其安全区域
1087浏览 • 1回复 待解决