HarmonyOS 如何全局避让手机底部的导航栏?

HarmonyOS 如何全局避让手机底部的导航栏?

HarmonyOS
2024-10-16 10:13:56
1440浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

HarmonyOS默认自动避让手机底部导航条,如果设置了setWindowLayoutFullScreen(true)设置了窗口全屏,可以在EntryAbility中获取并存储底部导航条高度:

onWindowStageCreate(windowStage: window.WindowStage) {  
  // Main window is created, set main page for this ability  
  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');  
  windowStage.loadContent('pages/Index', (err, data) => {  
    if (err.code) {  
      hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');  
      return;  
    }  
    hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');  
    let windowClass = windowStage.getMainWindowSync()  
    let bottomHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height  
    AppStorage.setOrCreate('bottomHeight',px2vp(bottomHeight));  
  });  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

并在需要的界面的最外层布局添加margin ,比如:

column().margin({ bottom: AppStorage.get('bottomHeight') })
  • 1.
分享
微博
QQ
微信
回复
2024-10-16 17:29:46
相关问题
HarmonyOS 获取手机底部导航高度
1107浏览 • 1回复 待解决
HarmonyOS Web组件安全避让导航
871浏览 • 1回复 待解决
HarmonyOS 如何获取底部导航高度?
975浏览 • 1回复 待解决
HarmonyOS 怎么去掉底部导航
1053浏览 • 1回复 待解决
HarmonyOS 如何让内容超出底部导航
639浏览 • 1回复 待解决
HarmonyOS 手机底部AI导航能否隐藏
860浏览 • 1回复 待解决
HarmonyOS 怎么设置无导航全局样式
744浏览 • 1回复 待解决
如何设置状态导航颜色
4501浏览 • 1回复 待解决