HarmonyOS 鸿蒙Next Beta5手机设置状态栏颜色失效
HarmonyOS 鸿蒙Next Beta5手机设置状态栏颜色失效
1、Beta2时使用如下方式修改状态栏颜色 显示正常:
window.getLastWindow(context).then((windowClass: window.Window) => {
try {
let sysBarProps: window.SystemBarProperties = {
statusBarColor: barColor,
};
// @ts-ignore
windowClass.setWindowSystemBarProperties(sysBarProps, (err: BusinessError) => {
let errCode: number = err.code;
if (errCode) {
console.error('Failed to set the system bar properties. Cause: ’ + JSON.stringify(err));
return;
}
console.info(‘Succeeded in setting the system bar properties.’);
});
} catch (exception) {
console.error(TAG, 'Failed to set the system bar properties. Cause: ’ + JSON.stringify(exception));
}
});
2、升级到Beta5后上述方式失效,根据Beta5开发文档(https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setwindowsystembarproperties9),进行设置,在Beta5手机上仍然不生效。代码如下:
- let windowClass: window.Window | undefined = undefined;
- windowStage.getMainWindow((err: BusinessError, data) => {
- const errCode: number = err.code;
- if (errCode) {
- console.error(
Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}
); - return;
- }
- windowClass = data;
- let SystemBarProperties: window.SystemBarProperties = {
- statusBarColor: ‘#ff00ff’,
- navigationBarColor: ‘#00ff00’,
- //以下两个属性从API Version8开始支持
- statusBarContentColor: ‘#ffffff’,
- navigationBarContentColor: ‘#00ffff’
- };
- try {
- let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties);
- promise.then(() => {
- console.info(‘Succeeded in setting the system bar properties.’);
- }).catch((err: BusinessError) => {
- console.error(
Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message}
); - });
- } catch (exception) {
- console.error(
Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message}
); - }
有遇到的吗?
关于HarmonyOS 鸿蒙Next Beta5手机设置状态栏颜色失效的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
3 回复
同样的问题,代码没动,现在状态栏背景色无效,状态栏文字颜色还可以。
我这边也是这样,Beta5中设置修改状态栏背景颜色无效了,只能设置状态栏内容字体颜色,之前Beta3时正常。