目录

页面和导航条区域的色调不一致

问题现象

应用未适配沉浸式显示,底部导航栏突兀。

背景知识

问题定位

  1. 全局搜索关键字setWindowLayoutFullScreen或expandSafeArea,查看应用页面是否设置为全屏模式。该页面使用setWindowLayoutFullScreen设置为全屏模式。
    aboutToAppear(): void {
      window.getLastWindow(this.getUIContext().getHostContext())
        .then(win => {
          win.setWindowLayoutFullScreen(true); // 设置全屏
        })
    }
  2. 全局搜索关键字setSpecificSystemBarEnabled,查看页面是否通过接口设置状态栏/导航栏的具体显示/隐藏状态。页面未使用setSpecificSystemBarEnabled方法对系统导航栏进行设置。
  3. 全局搜索关键字setWindowSystemBarProperties,查看页面是否设置状态栏导航栏样式。页面设置为导航栏背景色为白色。页面未使用setWindowSystemBarProperties对导航栏颜色等属性进行设置。

分析结论

当应用调用setWindowLayoutFullScreen接口设置窗口全屏布局时,未使用setSpecificSystemBarEnabled方法对系统导航栏进行隐藏,也未使用setWindowSystemBarProperties将导航栏颜色等属性与界面元素进行匹配。

修改建议

参考沉浸式页面实现实现页面沉浸式适配。

若需单独控制状态栏或导航栏的显示与隐藏,可在EntryAbility的onWindowStageCreate生命周期回调中调用setSpecificSystemBarEnabled接口进行设置:

import { window } from '@kit.ArkUI';

onWindowStageCreate(windowStage: window.WindowStage): void {
  let windowClass: window.Window = windowStage.getMainWindowSync();
  if (!windowClass) {
    console.info('windowClass is null');
    return;
  }
  try {
    windowClass.setSpecificSystemBarEnabled('status', false); // 隐藏状态栏
    windowClass.setSpecificSystemBarEnabled('navigationIndicator', false); // 隐藏导航条
  } catch (exception) {
    console.error(`Failed to set specific system bar enabled. Cause: ${JSON.stringify(exception)}`);
  }
  windowStage.loadContent('pages/Index', (err) => {
    // ...
  });
}