HarmonyOS 鸿蒙Next Beta5手机设置状态栏颜色失效

发布于 1周前 作者 gougou168 来自 鸿蒙OS

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手机上仍然不生效。代码如下:

  1. let windowClass: window.Window | undefined = undefined;
  2. windowStage.getMainWindow((err: BusinessError, data) => {
  3. const errCode: number = err.code;
  4. if (errCode) {
  5. console.error(Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message});
  6. return;
  7. }
  8. windowClass = data;
  9. let SystemBarProperties: window.SystemBarProperties = {
  10. statusBarColor: ‘#ff00ff’,
  11. navigationBarColor: ‘#00ff00’,
  12. //以下两个属性从API Version8开始支持
  13. statusBarContentColor: ‘#ffffff’,
  14. navigationBarContentColor: ‘#00ffff’
  15. };
  16. try {
  17. let promise = windowClass.setWindowSystemBarProperties(SystemBarProperties);
  18. promise.then(() => {
  19. console.info(‘Succeeded in setting the system bar properties.’);
  20. }).catch((err: BusinessError) => {
  21. console.error(Failed to set the system bar properties. Cause code: ${err.code}, message: ${err.message});
  22. });
  23. } catch (exception) {
  24. console.error(Failed to set the system bar properties. Cause code: ${exception.code}, message: ${exception.message});
  25. }

有遇到的吗?



关于HarmonyOS 鸿蒙Next Beta5手机设置状态栏颜色失效的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。

3 回复
同样的问题,代码没动,现在状态栏背景色无效,状态栏文字颜色还可以。
我这边也是这样,Beta5中设置修改状态栏背景颜色无效了,只能设置状态栏内容字体颜色,之前Beta3时正常。
回到顶部