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

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

阅读 620
1 个回答

请参考综合文档: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%')
    }
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进