期望效果:

实际效果:

全局搜索关键字setSpecificSystemBarEnabled和setWindowSystemBarEnable,查看页面是否通过接口设置状态栏导航栏的具体显示/隐藏状态。
aboutToAppear(): void {
let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
window.getLastWindow(context).then((lastWindow) => {
lastWindow.setSpecificSystemBarEnabled('navigationIndicator', false); // 设置导航栏隐藏
});
} aboutToAppear(): void {
let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
window.getLastWindow(context).then((lastWindow) => {
lastWindow.setWindowSystemBarEnable([]); // 设置导航栏隐藏
});
} 场景一:应用在不应该隐藏导航栏的界面,错误的使用setSpecificSystemBarEnabled方法对系统导航栏进行隐藏。
场景二:应用在不应该隐藏导航栏的界面,错误的使用setWindowSystemBarEnable方法对系统导航栏进行隐藏。
import { window } from '@kit.ArkUI';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct SituationOne {
aboutToAppear(): void {
let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
window.getLastWindow(context).then((lastWindow) => {
lastWindow.setSpecificSystemBarEnabled('navigationIndicator', true); // 设置导航栏显示
})
.catch((err: BusinessError) => {
console.error('Failed to get last window:', err);
});
}
build() {
Column() {
Text('Hello World')
.width('100%')
.height('100%')
.fontSize(30)
.textAlign(TextAlign.Center);
}
.width('100%')
.height('100%')
.padding({ top: 20 })
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]);
}
} 效果图如下:

import { window } from '@kit.ArkUI';
import { common } from '@kit.AbilityKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Entry
@Component
struct SituationTwo {
aboutToAppear(): void {
let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
window.getLastWindow(context).then((lastWindow) => {
lastWindow.setWindowSystemBarEnable(['status', 'navigation']); // 设置导航栏显示
})
.catch((err: BusinessError) => {
console.error('Failed to get last window:', err);
});
}
build() {
Column() {
Text('Hello World')
.width('100%')
.height('100%')
.fontSize(30)
.textAlign(TextAlign.Center);
}
.width('100%')
.height('100%')
.padding({ top: 20 })
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM]);
}
} 效果图如下:
