【问题标题】:How to make Android status bar light in Flutter如何在 Flutter 中让 Android 状态栏变亮
【发布时间】:2018-08-17 03:56:40
【问题描述】:

正如标题所示,这是关于 Flutter 的。

有没有什么办法可以将Android状态栏切换到浅色模式,让状态栏中的图标显示为暗色?以图片为例。

我尝试了以下可能的解决方案,但都没有奏效 -

// main.dart
appBar: new AppBar(
      brightness: Brightness.light,
      backgroundColor: Colors.white,
    ),

// MainActivity.kt
// Following 2 lines do change the color of status and nav bars
window.statusBarColor = 0x00000000
window.navigationBarColor = 0x00000000

// This seems to have no effect. Icons are still white.
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR


更新

对此的支持正在进行中 - https://github.com/flutter/flutter/issues/17231

【问题讨论】:

  • 您使用 AndroidManifest 执行此操作,而不是使用 dart 代码
  • 如何在 AndroidManifest 中做到这一点?此外,被标记为可能重复的问题是关于状态栏颜色的。这个问题与状态栏颜色无关。请注意<item name="android:windowLightStatusBar">true</item> 不同于<item name="android:statusBarColor">@color/whatever</item>
  • 我可以从 Dart 更改状态栏颜色。很有可能将其设置为来自 Dart 的默认较暗版本的 appbar 颜色。但我无法将其更改为浅色,因此其中的图标是深色的。

标签: android dart flutter


【解决方案1】:

Flutter 团队现在添加了对亮/暗状态栏控制的支持。要添加,请导入:

import 'package:flutter/services.dart';

然后在你的 App 的构建函数中添加这个:

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
  statusBarIconBrightness: Brightness.dark
));

【讨论】:

  • 在启动画面启动期间无论如何要这样做? (我猜不是)
【解决方案2】:

只是补充说明:

要将状态栏图标更改为深色,请输入以下代码

StatusBarIconBrightness: Brightness.light

并在 appbar 中添加亮度。

appBar: AppBar(  
brightness: Brightness.light, )

如果您想在状态栏上使用白色 bg,则更改为 .light 以便图标可以变暗,而 .dark 则更改为带有白色图标的较暗状态栏

【讨论】:

    猜你喜欢
    • 2017-10-08
    • 1970-01-01
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多