HarmonyOS NEXT API12以后配置沉浸式状态栏的方法
HarmonyOS NEXT API12以后配置沉浸式状态栏的方法
HarmonyOS NEXT API12 以前设置全屏状态栏可以使用 windowStage.getMainWindowSync().setWindowLayoutFullScreen,但是这个方法将在API12后废弃,虽然也可以使用,但是我们更推荐下面方法:
//参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5
// 沉浸式状态栏
let windowClass: window.Window | undefined = undefined;
windowStage.getMainWindow((err: BusinessError, data) => {
windowClass=data
let promise = windowClass.setWindowLayoutFullScreen(true);
promise.then(() => {
//设置状态栏透明背景
windowStage.getMainWindowSync().setWindowSystemBarEnable(['status']).then(() => {
const systemBarProperties: window.SystemBarProperties = {
statusBarColor: '#00000000'
};
//设置窗口内导航栏、状态栏的属性
windowStage.getMainWindowSync().setWindowSystemBarProperties(systemBarProperties)
.then(() => {
console.info('Succeeded in setting the system bar properties.');
}).catch((err:object) => {
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
});
})
}).catch((err: BusinessError) => {
console.error(`Failed to set the window layout to full-screen mode. Cause code: ${err.code}, message: ${err.message}`);
});
})