gpt4 book ai didi

android - 当我的应用重新聚焦时,如何更改导航栏图标颜色?

转载 作者:行者123 更新时间:2023-12-04 10:53:48 26 4
gpt4 key购买 nike

在我的应用程序中,我可以很好地设置状态栏和导航颜色。但是,我有多个屏幕,例如,当用户按下设备上的主页按钮,然后稍后恢复应用程序时,如何在他们恢复时更改导航栏的颜色?

我的具体问题是我的导航栏背景颜色为白色,当我退出应用程序并稍后恢复时,图标变为白色,使其无法看到。这是我的构建方法(去掉了不必要的代码)。除了这里,我不会在任何地方更改颜色。

@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white,
systemNavigationBarColor: Colors.white,
systemNavigationBarIconBrightness: Brightness.dark,
));
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0,
title: Text("App"),
centerTitle: true,
backgroundColor: Colors.white,
brightness: Brightness.light,
),
body: Container(),
);
}

下面是我的应用程序的图片,带有白色导航栏图标颜色。 actual result

这是它应该是什么样子的图像 expected result

最佳答案

本杰明,我能够在 Pixel 2 上重现您的问题。这很奇怪,这一定是某种系统错误,但您可以通过在应用从后台恢复时再次设置底部系统导航菜单颜色来修复它。为此,您需要检查您的 AppLifeCycleState如下所示,

class MyApp extends StatefulWidget {
@override
MyAppState createState() => MyAppState();
}

class MyAppState extends State<MyApp> with WidgetsBindingObserver {
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white,
systemNavigationBarColor: Colors.white,
systemNavigationBarIconBrightness: Brightness.dark,
));
}
}

@override
initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}

@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white,
systemNavigationBarColor: Colors.white,
systemNavigationBarIconBrightness: Brightness.dark,
));
return MaterialApp(
home: Scaffold(
appBar: AppBar(
elevation: 0,
title: Text("App", style: TextStyle(color: Colors.black)),
centerTitle: true,
backgroundColor: Colors.white,
brightness: Brightness.light,
actions: <Widget>[
Icon(
Icons.info_outline,
color: Colors.grey,
)
],
),
body: Center(
child: Column(
children: <Widget>[],
),
),
));
}
}

demo

关于android - 当我的应用重新聚焦时,如何更改导航栏图标颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59330076/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com