在HarmonyOS NEXT开发中状态栏怎么控制显示于隐藏,设置状态栏颜色,子颜色等控制?

在HarmonyOS NEXT开发中状态栏怎么控制显示于隐藏,设置状态栏颜色,子颜色等控制?

阅读 505
1 个回答

显示与隐藏 可以设置沉浸式,隐藏的话可以退出沉静式,在子窗口打开的页面 aboutToAppear 方法中设置沉浸式

aboutToAppear(): void { 
  // 设置沉浸式 
  window.getLastWindow(getContext(this), (err, windowBar) => { 
  windowBar.setWindowLayoutFullScreen(true); 
  // windowBar.setWindowSystemBarEnable([]) 
}) 
} 
aboutToDisappear(): void { 
  // 退出沉浸式 
  window.getLastWindow(getContext(this), (err, windowBar) => { 
  windowBar.setWindowLayoutFullScreen(false); 
  // windowBar.setWindowSystemBarEnable([]) 
}) 
}

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...
设置状态栏的背景:SystemBarProperties,参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...
或者使用

onWindowStageCreate(windowStage: window.WindowStage): void { 
  // Main window is created, set main page for this ability 
  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 
  windowStage.loadContent('pages/APage', (err) => { 
  if (err.code) { 
  hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 
  return; 
} 
windowStage.getMainWindowSync().setWindowBackgroundColor('#00ff33') ##此处添加 
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); 
}); 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进