简体   繁体   English

如何在Flutter应用程序中定位状态栏颜色或不透明度?

[英]How can I target status bar color or opacity in a Flutter app?

I couldn't find an attribute in the Scaffold or AppBar classes to do this. 我无法在Scaffold或AppBar类中找到属性来执行此操作。 Is it possible? 可能吗?

You can change the text color of the status bar from light to dark using SystemChrome.setSystemUIOverlayStyle . 您可以使用SystemChrome.setSystemUIOverlayStyle将状态栏的文本颜色从浅色更改为深色。 For example, to make the status bar font black: 例如,要使状态栏字体变为黑色:

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);

However, the AppBar widget also calls setSystemUIOverlayStyle in its build function and may interfere with you. 但是, AppBar小部件还在其构建函数中调用setSystemUIOverlayStyle并可能会干扰您。 If you're building an app that uses AppBar widget, you should probably set the brightness on your AppBar to be Brightness.dark (if you want a light text status bar) or Brightness.light (if you want a dark text status bar). 如果你正在构建一个使用AppBar小部件的应用程序,你可能应该将AppBar上的brightness设置为Brightness.dark(如果你想要一个浅色文本状态栏)或Brightness.light(如果你想要一个暗文本状态栏) 。

To hide the status indicator entirely, use SystemChrome.setEnabledSystemUIOverlays . 要完全隐藏状态指示器,请使用SystemChrome.setEnabledSystemUIOverlays

I'm not sure if Flutter has an API for customize the text opacity or background color. 我不确定Flutter是否有用于自定义文本不透明度或背景颜色的API。 There isn't a background at all on iOS, but you could draw one yourself. 在iOS上根本没有背景,但你可以自己画一个。

  // set status bar color with opacity
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(
      statusBarColor: Color(0x22CACACA)
  ));
  1. You can set status bar color( CACACA part after 0x22 ). 您可以设置状态栏颜色( 0x22后的CACACA部分)。
  2. You can set color opacity( 22 part after 0x ). 您可以设置颜色不透明度( 0x后的22部分)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM