[英]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)
));
CACACA
part after 0x22
). 0x22
后的CACACA
部分)。 22
part after 0x
). 0x
后的22
部分)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.