HarmonyOS 深色模式后状态栏看不到状态信息(时间、电量等)

HarmonyOS
6h前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple
import { AbilityConstant, Configuration, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';

export default class EntryAbility extends UIAbility {
  colorMode: number | undefined = 0

  onConfigurationUpdate(newConfig: Configuration): void {
    this.colorMode = newConfig.colorMode
    let windowStage: window.WindowStage | undefined = AppStorage.get('windowStage')
    if (windowStage !== undefined) {
      this.changeColor(windowStage)
    }
  }


  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
    this.colorMode = this.context.config.colorMode
  }

  onDestroy(): void {
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
  }

  changeColor(windowStage: window.WindowStage) {
    let windowClass: window.Window | null
    windowStage.getMainWindow((err: BusinessError, data) => {
      let errCode: number = err.code;
      if (errCode) {
        console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
        return;
      }
      windowClass = data;
      console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));

      let sysBarProps: window.SystemBarProperties = {
        statusBarColor: this.colorMode === 0 ? '#aa00ff0b' : '#ff00ff',
        navigationBarColor: '#00ff00',
        // 以下两个属性从API Version 8开始支持
        statusBarContentColor: this.colorMode === 0 ? '#aaff0000' : '#ff002aff',
        navigationBarContentColor: '#ffffff'
      };
      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.');
      });
    })
  }


  onWindowStageCreate(windowStage: window.WindowStage): void {
    // Main window is created, set main page for this ability
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
    AppStorage.setOrCreate('windowStage', windowStage)

    this.changeColor(windowStage)

    windowStage.loadContent('pages/Index', (err) => {
      if (err.code) {
        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
        return;
      }
      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
    });


  }

  onWindowStageDestroy(): void {
    // Main window is destroyed, release UI related resources
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
  }

  onForeground(): void {
    // Ability has brought to foreground

    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
  }

  onBackground(): void {
    // Ability has back to background
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
  }
}
分享
微博
QQ
微信
回复
4h前
相关问题
求获取状态栏高度方法
8083浏览 • 1回复 待解决
沉侵式状态栏获取状态栏高度为0
389浏览 • 1回复 待解决
HarmonyOS 沉浸式状态栏
108浏览 • 1回复 待解决
HarmonyOS API获取状态栏高度
299浏览 • 1回复 待解决
HarmonyOS 如何获取状态栏高度
607浏览 • 1回复 待解决
HarmonyOS 下拉如何隐藏状态栏
17浏览 • 1回复 待解决
获取状态栏与导航高度
636浏览 • 1回复 待解决
HarmonyOS 如何获取系统状态栏高度?
825浏览 • 1回复 待解决
HarmonyOS 修改状态栏颜色不生效
303浏览 • 1回复 待解决
HarmonyOS 如何获取手机状态栏高度?
159浏览 • 1回复 待解决
HarmonyOS 沉浸式状态栏最佳实践
294浏览 • 1回复 待解决
如何获取状态栏和导航高度
2909浏览 • 1回复 待解决
如何获取状态栏与导航高度?
232浏览 • 0回复 待解决
获取状态栏高度的方法
1970浏览 • 1回复 待解决
如何实现沉浸式状态栏
524浏览 • 1回复 待解决
如何设置沉浸式状态栏
2569浏览 • 1回复 待解决