HarmonyOS 底部系统导航条怎么适配?

HarmonyOS
2024-12-24 16:26:53
296浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

请参考综合文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-develop-apply-immersive-effects-V5#section15671730447

window.getLastWindow()获取的是最上层的子窗口,需要用windowStage.getMainWindowSync(); // 获取应用主窗口在获取导航栏高度。AvoidAreaType.TYPE_NAVIGATION_INDICATOR表示导航条区域。

let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; 
  • 1.

也可以采用设置安全区域expandSafeArea的方法。https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-expand-safe-area-V5

参考文档:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-develop-apply-immersive-effects-V5#section15671730447

示例参考:

// xxx.ets
import web_webview from '@ohos.web.webview';
import business_error, { BusinessError } from '@ohos.base';
import { window } from '@kit.ArkUI';

@Entry
@Component
struct WebComponent {
  controller: web_webview.WebviewController = new web_webview.WebviewController();
  @State topSafeHeight: number = 0;
  aboutToAppear(): void {
    try {
      let windowClass: window.Window | undefined = undefined;
      window.getLastWindow(getContext(this), (err: BusinessError, data) => {
        const errCode: number = err.code;
        if (errCode) {
          console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(err));
          return;
        }
        windowClass = data;
        windowClass.setWindowLayoutFullScreen(true);
        this.topSafeHeight = px2vp(windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height);
        windowClass.on('avoidAreaChange', (data) => {
          if (data.type == window.AvoidAreaType.TYPE_SYSTEM) {
            this.topSafeHeight = px2vp(data.area.topRect.height)
          }
        })
        console.info('Succeeded in obtaining the top window. Data: ' + JSON.stringify(data));
      });
    } catch (exception) {
      console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(exception));
    }
  }

  build() {
    Column() {
      Row() {
      }
      .height(this.topSafeHeight)
      .width("100%")
      Row(){
        Text("Hello world")
          .width("100%")
          .height(50)
      }
      Web({ controller: this.controller, src: "www.huawei.com" }).height('100%').width('100%')
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
分享
微博
QQ
微信
回复
2024-12-24 18:36:45


相关问题
HarmonyOS 怎么隐藏底部导航条
720浏览 • 1回复 待解决
适配底部导航条,会出现遮挡情况
2973浏览 • 1回复 待解决
HarmonyOS 无法隐藏底部导航条
817浏览 • 1回复 待解决
HarmonyOS 底部导航条沉浸式方案
949浏览 • 1回复 待解决
HarmonyOS 导航条沉浸式未适配
731浏览 • 1回复 待解决
HarmonyOS h5导航条适配方案
1030浏览 • 1回复 待解决
HarmonyOS 怎么去掉底部导航
1033浏览 • 1回复 待解决