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

HarmonyOS
2天前
浏览
收藏 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; 

也可以采用设置安全区域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%')
    }
  }
}
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS 怎么隐藏底部导航条
25浏览 • 1回复 待解决
适配底部导航条,会出现遮挡情况
2014浏览 • 1回复 待解决
HarmonyOS 底部导航条沉浸式方案
329浏览 • 1回复 待解决
HarmonyOS h5导航条适配方案
14浏览 • 1回复 待解决
HarmonyOS 怎么去掉底部导航
83浏览 • 1回复 待解决