如何在Flutter中更改本机启动屏幕状态栏的颜色?

3

我想在安卓和iOS本地闪屏页面中根据移动设备的暗黑模式和明亮模式来更改状态栏颜色。本地闪屏页面使用flutter_native_splash : ^2.2.0+1生成。

我尝试过以下方法,但在安卓上并没有起作用,在res/night/styles.xml中:

<item name="android:statusBarColor">@android:color/white</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowLightStatusBar">true</item>

splash screen screenshots


1
这是您要找的内容吗?https://dev59.com/r1QK5IYBdhLWcg3wF8B6 - Jungwon
不,我正在尝试更改本机启动画面的颜色。 - Renik Shiroya
它会影响整个应用程序。我只需要针对应用程序中的本机启动画面。 - Renik Shiroya
我在其他屏幕中使用了Colorfulsafearea。 - Renik Shiroya
请编写自己的最小可执行源代码。 - Jungwon
2个回答

8

在res文件夹中的values/styles.xml和values-night/styles.xml文件中添加以下代码即可解决问题:

  <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             the Flutter engine draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:forceDarkAllowed">false</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:windowLightStatusBar">true</item>
    </style>

2

默认的本地启动画面不是全屏的。要使其全屏,您需要在yaml文件中使用fullscreen: true

flutter_native_splash:
  fullscreen: true

要隐藏通知栏,请使用全屏参数。在Web上没有通知栏,因此没有影响。
默认值为false。

注意:与Android不同,iOS不会在应用程序加载时自动显示通知栏。 要显示通知栏,请将以下代码添加到您的Flutter应用程序中:

WidgetsFlutterBinding.ensureInitialized();
       SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);

更多信息和参考资料请访问flutter_native_splash


它可以工作,但只有在应用程序重新启动时才会显示黑色状态栏。 - Renik Shiroya
确保正确退出应用程序,否则它将从“onResume”生命周期开始而不是“onCreate”生命周期。 - Yeasin Sheikh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接