HarmonyOS 如何获取状态栏的背景色和字体颜色呢?

如何获取状态栏的背景色和字体颜色呢?

HarmonyOS
2024-12-20 15:50:12
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setwindowsystembarproperties9

setWindowLayoutFullScreen 设置全屏导航栏颜色随页面颜色变化

import { router, window } from '@kit.ArkUI';
import { common } from '@kit.AbilityKit';

@Entry
@Component
struct SystemBarPropertiesTest {
  @State message: string = 'Hello World';
  @State barHeight: number = 0;
  private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;

  async setSystemBar() {
    // 获取当前应用窗口
    let windowClass: window.Window = await window.getLastWindow(this.context)
    // 获取状态栏高度
    this.barHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height
    // 前提:设置窗口为全屏窗口
    windowClass.setWindowLayoutFullScreen(true);
    // 沉浸式方案一:设置系统栏不显示[],需要显示则设置[‘status’,‘navigation’]
    // windowClass.setWindowSystemBarEnable([]);
    // 沉浸式方案二:将状态栏和导航栏的背景色设置为跟应用窗口相同的颜色
    /*await windowClass.setWindowSystemBarProperties({
    // 颜色属性为ARGB,将蒙尘设置为0%使其透明
    // 导航栏颜色
    navigationBarColor: "#fd121de5",
    // 状态栏颜色
    statusBarColor: "#ff0ad9c2",
    // 导航栏文字颜色
    navigationBarContentColor: "#fde20606",
    // 状态栏文字颜色
    statusBarContentColor: "#fff1e50a"
    })*/

  }

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(()=>{
            this.setSystemBar()
          })
      }
      .width('100%')
    }
    .height('100%')
    .backgroundColor(Color.Brown)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
分享
微博
QQ
微信
回复
2024-12-20 18:42:44
相关问题
鸿蒙怎么 修改状态栏字体颜色
13525浏览 • 1回复 待解决
如何设置状态栏导航颜色
4514浏览 • 1回复 待解决
状态栏高度怎么获取
10183浏览 • 3回复 待解决
HarmonyOS 状态栏颜色如何修改
1439浏览 • 1回复 待解决
如何获取状态栏导航高度
3938浏览 • 1回复 待解决
HarmonyOS 如何设置状态栏颜色
1046浏览 • 1回复 待解决
如何设置WebView背景色
1635浏览 • 1回复 待解决
如何设置窗口背景色
2602浏览 • 1回复 待解决
HarmonyOS 如何设置渐变背景色
2267浏览 • 1回复 待解决
如何获取系统导航状态栏高度
1965浏览 • 1回复 待解决