[英]Flutter statusbar color on startup
When my app loads it goes through 3 phases and I'm trying to figure out how to make them consistent.当我的应用程序加载时,它会经历 3 个阶段,我试图弄清楚如何使它们保持一致。
Flutter Splash screen? Flutter 闪屏?
I am trying to get all three of these to be the last one (white header), but am having trouble getting it to work (especially the grey bar)我试图让这三个都成为最后一个(白色标题),但无法让它工作(尤其是灰色条)
<?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>
No matter what statusBarColor is, the bar starts black无论 statusBarColor 是什么,条形开始为黑色
windowLightStatusBar turns the icons black (which feels like progress) windowLightStatusBar 将图标变为黑色(感觉像是进步)
windowDrawSystemBarBackgrounds DOES change the bar white, however the image that is centered shifts down (which I guess makes sense, apps not incharge of that space?) windowDrawSystemBarBackgrounds 确实将条形图更改为白色,但是居中的图像会向下移动(我想这是有道理的,应用程序不负责该空间?)
If I use the above option the grey header still appears AND the centered image shifts when it switches from the first to second phase.如果我使用上述选项,灰色 header 仍然出现,并且当它从第一阶段切换到第二阶段时,中心图像会移动。
I currently have no idea how to fix the grey header.我目前不知道如何修复灰色 header。
Launch_background.xml 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 Manifest 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" />
In Flutter on my view I have在我看来,Flutter
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.dark,
),
);
It's actually a bug in flutter engine, https://github.com/flutter/flutter/issues/64001这实际上是 flutter 引擎中的一个错误, https://github.com/flutter/flutter/issues/64001
Flutter hard coded that grey status bar, which is stupid and very hard to find. Flutter 硬编码了那个灰色状态栏,这很愚蠢而且很难找到。 Wasted hours to even locate this bug.
甚至浪费了几个小时来定位这个错误。
The way to solve it is like this解决方法是这样的
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);
}
} }
Then you can set your own color and style!然后你可以设置自己的颜色和风格!
I think you should set the android:statusBarColor
to @android:color/white
but not transparent.我认为您应该将
android:statusBarColor
设置为@android:color/white
但不透明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.