HarmonyOS NEX 鸿蒙改变状态栏和安全区域颜色

在目录EntryAbility下onWindowStageCreate下 初始化

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

  let windowClass: window.Window | null = null;
  windowStage.getMainWindow((err: BusinessError, data) => {
    windowClass = data;
    let sysBarProps: window.SystemBarProperties = {
      statusBarContentColor: '#FFFFFF'
    };
    // 2.设置窗口内导航栏、状态栏属性。systemBarProperties:导航栏、状态栏的属性集合
    windowClass.setWindowSystemBarProperties(sysBarProps);
  })

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

  AppStorage.setOrCreate('windowStage',windowStage);
}

在页面中修改

import { window } from '@kit.ArkUI'

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

aboutToAppear(): void {
  let sysBarProps: window.SystemBarProperties = {
    statusBarContentColor: '#000000'
  };
  this.mainWin.setWindowSystemBarProperties(sysBarProps);

}

沉浸式

build() {
  Column(){
  }
  .backgroundColor('#3C7FFF')
  .height('100%')
  .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP]) // 页面Navigation沉浸式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值