我想根据主题改变systemNavigationBar的颜色。
我一直试图用SystemOverlayStyle
改变应用程序的系统导航颜色,但它似乎不起作用。
ThemeData get light => ThemeData(
appBarTheme: AppBarTheme(
iconTheme: lightBase.iconTheme,
backgroundColor: Colors.transparent,
elevation: 0,
centerTitle: true,
titleTextStyle: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 17,
color: AppColors.textDark,
),
systemOverlayStyle:
SystemUiOverlayStyle(systemNavigationBarColor: Colors.pink),
),
);
输出:
发布于 2022-07-14 07:52:22
用Scaffold
小部件包装AnnotatedRegion
。然后将其值属性设置为SystemUIOverlayStyle
例如
@override
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: const SystemUiOverlayStyle(
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark,
statusBarColor: Colors.transparent,
systemNavigationBarColor: Colors.white, // Change Background color
systemNavigationBarIconBrightness: Brightness.dark, // Change Icon color
),
child: Scaffold(
要动态更改(例如,使用系统主题),首先获取系统的Brightness
。
var brightness = MediaQuery.of(context).platformBrightness;
bool isDarkMode = brightness == Brightness.dark;
现在基于isDarkMode
值
systemNavigationBarColor:isDarkMode ? Colors.white : Colors.black,
发布于 2022-07-14 05:20:21
使用manifest.xml文件(在android项目中)
https://developer.android.com/reference/android/view/Window#setNavigationBarColor(int)
https://stackoverflow.com/questions/72975520
复制相似问题