【问题标题】:Flutter: How to change the status bar text color on Android and iOS when not using AppBar [duplicate]Flutter:不使用AppBar时如何在Android和iOS上更改状态栏文本颜色[重复]
【发布时间】:2020-09-03 04:47:30
【问题描述】:

我是 Flutter 的新手,我在 Google 上搜索过这个问题,但没有找到适合我的答案。

我的代码如下所示,状态栏颜色很好,现在是白色的。但是Android上的状态栏文字颜色也是白色的,好像Brightness.dark根本不起作用...

您的回答将不胜感激,谢谢!

Widget build(BuildContext context) {

 SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
   statusBarColor: Colors.white, // Color for Android
   statusBarBrightness: Brightness.dark // Dark == white status bar -- for IOS.
 ));

 return Scaffold(
   body: Container(
     ...
}

【问题讨论】:

  • 请检查这个答案:stackoverflow.com/a/61025717/7666442
  • 嗨@NileshRathod,谢谢你的建议。我在发布问题之前尝试了您的答案,但它不适用于我的情况,错误一直显示 Utils 未定义:( 你知道为什么吗?
  • 我在和Utils 类中定义了Brightness.darkBrightness.light 作为常量,这就是我使用Utils.androidWhiteIcon 的原因
  • 大声笑,我明白了,顺便说一句,我发现下面的答案就像魅力一样!无论如何,谢谢你!
  • 顺便说一句 @NileshRathod 你能删除我问题的[重复]标签吗?因为这与您提供的链接提出的问题并不完全相同。 @@ 那是询问更改状态栏颜色,而不是更改状态栏文本颜色。

标签: android ios flutter


【解决方案1】:

根据SystemUiOverLayStyle API docs,Android 上状态栏的文字颜色不能被statusBarBrightness 改变,只有iOS 支持。

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.white,               // Only honored in Android M and above
      statusBarIconBrightness: Brightness.dark   // Only honored in Android M and above
      statusBarBrightness: Brightness.light,      // Only honored in iOS
));

希望这会有所帮助!干杯

【讨论】:

    猜你喜欢
    • 2019-12-22
    • 2021-06-26
    • 2019-01-13
    • 2013-10-04
    • 2019-11-01
    • 2020-02-04
    • 2019-12-31
    • 2018-11-03
    • 2013-07-14
    相关资源
    最近更新 更多