启动时颤振状态栏颜色

时间:2020-07-02 15:32:50

标签: android flutter

当我的应用加载时,它经历了三个阶段,我试图弄清楚如何使它们保持一致。

启动 enter image description here

Flutter Splash屏幕? 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 个答案:

答案 0 :(得分:1)

这实际上是颤振引擎中的错误, https://github.com/flutter/flutter/issues/64001

Flutter硬编码了该灰色状态栏,该状态栏很愚蠢,很难找到。浪费了数小时甚至找不到此错误。

解决方法是这样的

// class level variable
NSObject observer;

// register as observer
public override void ViewWillAppear (bool animated)
{
    base.ViewWillAppear (animated);
    observer = NSNotificationCenter.DefaultCenter.AddObserver ((NSString)UIDevice.OrientationDidChangeNotification, OrientationChanged);
}

// deregister as observer
public override void ViewDidDisappear (bool animated)
{
    base.ViewDidDisappear (animated);
    if (observer != null) { 
        NSNotificationCenter.DefaultCenter.RemoveObserver (observer);
        observer = null;
    }
}

// function which should do something when notification is received
public void OrientationChanged(NSNotification notification){
    Console.WriteLine ("test");
    // perhaps you can do the following as in the linked SO question: NSObject myObject = notification.Object;
}

}

然后您可以设置自己的颜色和样式!

答案 1 :(得分:0)

我认为您应该将android:statusBarColor设置为@android:color/white,但不要透明。