HarmonyOS 鸿蒙Next状态栏设置颜色失效
HarmonyOS 鸿蒙Next状态栏设置颜色失效
setStatusBarColor(this.localSetting.isNight ? ‘#f00’ : ‘#f00’)
/**
- 设置状态栏颜色
- @param color
*/
export function setStatusBarColor(color: string) {
let windowClass: window.Window | undefined = undefined;
try {
let promise = window.getLastWindow(getContext());
promise.then((data) => {
windowClass = data;
windowClass.setWindowSystemBarProperties({ statusBarColor: color, statusBarContentColor: color,
navigationBarColor: color, navigationBarContentColor: color })
console.info('Succeeded in obtaining the top window. Data: ’ + JSON.stringify(data));
}).catch((err: BusinessError) => {
console.error('Failed to obtain the top window. Cause: ’ + JSON.stringify(err));
});
} catch (exception) {
console.error('Failed to obtain the top window. Cause: ’ + JSON.stringify(exception));
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
关于HarmonyOS 鸿蒙Next状态栏设置颜色失效的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
5 回复
将颜色设置改位6位的模式,比如红色改“#ff0000”
我想问除了getLastWindow还有其它方式获取到主窗口吗,这个方法有可能获取到的是其它子窗口
直接把ability里面拿到的window存到appstorage里面 随时去取就行了
手机升级到Beta5后,该方法失效,遇到过吗