[英]How to change the status bar icons and text color to black in flutter?
I am using white background for App Bar in flutter and how can I change the status bar icon colors to black,我在颤动中为 App Bar 使用白色背景,如何将状态栏图标颜色更改为黑色,
I am using this code to change the status bar color,我正在使用此代码更改状态栏颜色,
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Colors.white,
statusBarIconBrightness: Brightness.light,
));
You also need to set to brightness
in AppBar if you are using one.如果您正在使用,您还需要在 AppBar 中设置为brightness
。 Eg.例如。
appBar: AppBar(
backgroundColor: Colors.white,
brightness: Brightness.dark,
),
You can checkout detailed answer here: How to change status bar color in Flutter?您可以在此处查看详细答案: 如何在 Flutter 中更改状态栏颜色?
Brightness
was obsolete)嗨,在我的项目中,我使用以下(使用Brightness
已过时)return AnnotatedRegion<SystemUiOverlayStyle>(
//Set status bar icon color
value: your_condition
? SystemUiOverlayStyle.dark.copyWith(
statusBarColor: your_color,
//statusBarIconBrightness: Brightness.light,
)
: SystemUiOverlayStyle.light.copyWith(
statusBarColor: your_color,
//statusBarIconBrightness: Brightness.light,
),
child: your_widget);
return AppBar(
elevation: 0.0,
systemOverlayStyle: your_condition ? SystemUiOverlayStyle.dark : SystemUiOverlayStyle.light,
backgroundColor: your_color,
);
Flutter 2.4.0+ UPDATE颤振 2.4.0+ 更新
Since flutter 2.4.0 brightness: Brightness.dark
is deprecated.由于颤振 2.4.0 brightness: Brightness.dark
不推荐使用brightness: Brightness.dark
。
It has been replaced by systemOverlayStyle: SystemUiOverlayStyle.dark
它已被systemOverlayStyle: SystemUiOverlayStyle.dark
取代systemOverlayStyle: SystemUiOverlayStyle.dark
How to use:如何使用:
import 'package:flutter/services.dart';
appBar: AppBar(
systemOverlayStyle: SystemUiOverlayStyle.dark,
elevation: 0.0,
),
Set SystemUiOverlayStyle.dark
if you want black icons.如果需要黑色图标,请设置SystemUiOverlayStyle.dark
。
Set SystemUiOverlayStyle.light
if you want white icons.如果需要白色图标,请设置SystemUiOverlayStyle.light
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.