鸿蒙顶部状态栏设置固定的背景颜色和字体颜色

1、在EntryAbility中对windowStage进行本地存储:

AppStorage.setOrCreate('windowStage', windowStage);

在这里插入图片描述

2、首页中新增如下代码:

 windowStage: window.WindowStage = AppStorage.get("windowStage") as window.WindowStage;
 mainWin: window.Window = this.windowStage.getMainWindowSync();

在这里插入图片描述

3、在首页的aboutToAppear初始化方法中写入如下代码:

  aboutToAppear(): void {
    // 配置Web开启调试模式
    web_webview.WebviewController.setWebDebuggingAccess(true);

    //深色模式_配置状态栏
    let sysBarProps: window.SystemBarProperties = {
      statusBarColor: '#ffffff', //背景颜色
      statusBarContentColor: '#000000'//字体颜色
    };
    this.mainWin.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内顶部的白色背景重合,此时就会出现深色模式下,app内状态栏内的文字无法看到的bug,用上面的方法是强制给状态栏的背景设为白色,字体设为黑色,不受系统深色模式的影响,当然,如果有时间把app适配上系统的深色模式更佳!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值