使用SystemBarProperties自定义状态栏颜色。如下实现:
/**
* @describe : 设置状态栏颜色
* @param color string颜色
*/
static setStatusBarColor(color: string) {
let sysBarProps: window.SystemBarProperties = {
statusBarColor: color,
};
const mainWindow = CommonManager.getInstance().getWindowStage()?.getMainWindowSync()
mainWindow?.setWindowSystemBarProperties(sysBarProps, (err: BusinessError) => {
let errCode: number = err.code;
if (errCode) {
console.error('[StaticUtils] Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
return;
}
console.info('[StaticUtils] Succeeded in setting the system bar properties.');
});
}
当设置了自定义状态栏颜色后拖动app到后台会显示 app与状态栏分离。可以参考下面截图。如何实现自定义状态栏颜色但是不产生分离效果
可以尝试可以将状态栏改成了透明,窗口做成全屏化布局,然后在页面上添加了一个状态栏高度的blank并且填充颜色