简体   繁体   English

当我们使用AppBar时,如何在Flutter中更改状态栏的颜色?

[英]How to change the Status Bar color in Flutter when we are using an AppBar?

I know we can change the Status Bar using: 我知道我们可以使用以下方式更改状态栏:

But the docs mention the AppBar will set the Status Bar color automatically, so the question I have is, how do I set the Status Bar color, when I have an AppBar in place, but I want to define a specific color myself and not let the AppBar do it automatically? 但是文档提到AppBar会自动设置状态栏颜色,所以我的问题是,当我有一个AppBar时,如何设置状态栏颜色,但是我想自己定义一个特定的颜色而不是让AppBar自动执行吗?

I want to define a specific color myself and not let the AppBar do it automatically? 我想自己定义一种特定的颜色,而不是让AppBar自动进行设置吗?

Using SystemChrome will override the Appbar setting. 使用SystemChrome将覆盖应用栏设置。

If you want to set the color yourself use the following function you already mentioned once or in an initstate function. 如果要自己设置颜色,请使用下面已经提到过的函数或initstate函数。

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  statusBarColor: Colors.yellow.shade600,
  statusBarBrightness: Brightness.light,
  statusBarIconBrightness: Brightness.dark,
));

This will override the Appbar setting 这将覆盖应用栏设置

Additional Note: Status bar Icon Color 附加说明:状态栏图标颜色

if the status bar icon not changing to dark or light mode. 如果状态栏图标未更改为暗或亮模式。 Make sure to add brightness in appbar. 确保在应用栏中添加亮度。

appbar :Appbar (
 brightness: Brightness.light,),

Can be change to .dark or .light as above 可以如上所述更改为.dark或.light

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

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