簡體   English   中英

如何在顫動中更改原生閃屏的狀態欄顏色?

[英]How to change status bar color of native splash screen in flutter?

我想根據移動設備中的深色模式和淺色模式更改 android 和 ios Native 初始屏幕中的狀態欄顏色。 使用flutter_native_splash : ^2.2.0+1

我嘗試了下面的東西,但在 res/night/styles.xml 中的 android 中不起作用

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

閃屏截圖

通過在 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>

默認本機啟動畫面不是全屏。 要啟用全屏,您需要在 yaml 文件中使用fullscreen: true

flutter_native_splash:
  fullscreen: true

要隱藏通知欄,請使用 fullscreen 參數。 由於網頁沒有通知欄,因此在網頁中無效。
默認為假。

注意:與 Android 不同,iOS 不會在應用加載時自動顯示通知欄。 要顯示通知欄,請將以下代碼添加到您的 Flutter 應用程序中:

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

更多和參考flutter_native_splash

將此代碼添加到 res 文件夾中的 values/styles.xml 和 values-night/styles.xml

<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM