在 main.dart
void main() {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.black.withOpacity(0), //top bar color
statusBarIconBrightness: Brightness.dark, //top bar icons
systemNavigationBarColor: Colors.black, //bottom bar color
systemNavigationBarIconBrightness: Brightness.light, //bottom bar icons
),
);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
//primaryColor: Color.fromRGBO(113, 201, 206, 1),
fontFamily: 'Montserrat',
textTheme: TextTheme(
headline: TextStyle(
fontSize: 40,
fontWeight: FontWeight.w500,
),
title: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 16,
),
body1: TextStyle(
fontSize: 12,
),
),
),
home: Test(),
routes: {
MainScreen.routeName: (context) => MainScreen(),
},
);
}
}
我使用上面的代码来改变状态栏的颜色,
statusBarIconBrightness: Brightness.dark
没有效果。它变成黑色,但几秒钟后又切换回“Brightness.light”。
怎么了?
在 Android 模拟器上运行。
我不想有
appBar
在 Test()
小部件。
最佳答案
那是因为您没有明确更改 AppBar
的 brightness
在您的 Test
页。运行此代码并查看差异:
void main() {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.black.withOpacity(0), //top bar color
// statusBarIconBrightness: Brightness.dark, // don't use this
),
);
runApp(MyApp2());
}
class MyApp2 extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("AppBar"),
brightness: Brightness.light, // use this instead
),
),
);
}
}
输出 1(亮度.暗):
输出 2(亮度.光):
关于flutter - 无法在flutter应用程序中更改状态栏图标亮度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59170915/