Flutter启动时状态栏颜色

9
当我的应用程序加载时,它经历了3个阶段,我正在尝试弄清楚如何使它们保持一致。
启动 enter image description here Flutter启动画面? enter image description here 主应用程序页面 enter image description here 我正在尝试让它们全部变成最后一个(白色标题),但是我无法让它正常工作(特别是灰色条)。
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
        <!-- <item name="android:windowLightStatusBar">true</item>  -->
        <!-- <item name="android:windowDrawsSystemBarBackgrounds">true</item> -->
        <!-- <item name="android:statusBarColor">@android:color/transparent</item> -->
    </style>
</resources>

无论statusBarColor是什么,状态栏都会开始变成黑色。
windowLightStatusBar会使图标变黑(这感觉像是进步)。
windowDrawSystemBarBackgrounds确实会将状态栏变为白色,但是居中的图像会向下移动(我猜这是有道理的,因为应用程序不控制那个空间?)。
如果我使用上述选项,灰色的标题仍然出现,并且当它从第一阶段切换到第二阶段时,中心图像会移动。
我目前不知道如何解决灰色标题问题。
Launch_background.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/logo" />
    </item>
</layer-list>

Android清单文件

<activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:windowSoftInputMode="adjustResize">
        <!-- This keeps the window background of the activity showing
             until Flutter renders its first frame. It can be removed if
             there is no splash screen (such as the default splash screen
             defined in @style/LaunchTheme). -->
        <meta-data
            android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
            android:value="true" />

在Flutter中,我的视图上有:
SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarIconBrightness: Brightness.dark,
        statusBarBrightness: Brightness.dark,
      ),
    );
2个回答

5

实际上这是flutter引擎中的一个bug, https://github.com/flutter/flutter/issues/64001

Flutter在代码中硬编码了这个灰色状态栏,这非常愚蠢而且很难找。浪费了好几个小时才找到这个bug。

解决方法如下:

public class MainActivity extends FlutterActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //https://github.com/flutter/flutter/issues/64001 
    Window window = getWindow();
    window.setStatusBarColor(0x00000000);
    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

}

然后你就可以设置自己的颜色和样式了!


0

我认为你应该将android:statusBarColor设置为@android:color/white而不是透明。


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