如何设置状态栏和导航栏的颜色?

如何设置状态栏和导航栏的颜色

阅读 909
1 个回答

使用window.setWindowSystemBarProperties()接口即可设置。

示例代码

Text(this.message) 
  .fontSize(50) 
  .fontWeight(FontWeight.Bold) 
  .onClick(()=>{ 
    window.getLastWindow(getContext(this),(err,win)=>{ 
      // TYPE_CUTOUT表示刘海屏区域。 
      let cutOutInfo=win.getWindowAvoidArea(window.AvoidAreaType.TYPE_CUTOUT); 
      console.log(JSON.stringify(cutOutInfo)); 
      // TYPE_SYSTEM 表示系统默认区域。一般包括状态栏、导航栏,各设备系统定义可能不同。 
      let systemArea = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM); 
      console.log(JSON.stringify(systemArea)); 
      // 设置导航栏状态栏颜色 
      win.setWindowSystemBarProperties({ 
        // 状态栏颜色 
        statusBarColor:'#66666666', 
        // 状态栏文字颜色 
        statusBarContentColor:'#ffffffff', 
        // 导航栏颜色 
        navigationBarColor:'#ff000000', 
        // 导航栏文字颜色 
        navigationBarContentColor:'#ffffffff' 
      }) 
    }) 
  })
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进