【发布时间】:2020-03-28 22:54:34
【问题描述】:
在 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 模拟器上运行。
我不想在 Test() 小部件中使用 appBar。
【问题讨论】:
-
你的代码很完美,但是在返回脚手架之前尝试在 MyApp 类中使用你上面的代码
-
你在模拟器上试试吗?或真实的设备。如果是模拟器,那么是哪个安卓或苹果。这仅适用于 android。
-
问题已更新