【问题标题】:Flutter statusbar color on startup启动时颤动状态栏颜色
【发布时间】:2020-10-23 06:22:33
【问题描述】:

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

启动

Flutter 启动画面?

主应用页面

我试图让这三个都成为最后一个(白色标题),但无法让它工作(尤其是灰色条)

<?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,
      ),
    );

【问题讨论】:

    标签: android flutter


    【解决方案1】:

    其实是flutter引擎的一个bug, https://github.com/flutter/flutter/issues/64001

    Flutter 对那个灰色状态栏进行了硬编码,这很愚蠢而且很难找到。甚至浪费了几个小时来定位这个错误。

    解决方法是这样的

    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);
    
    }
    

    }

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2021-12-17
        • 2019-10-03
        • 1970-01-01
        • 2021-04-13
        • 2021-04-19
        • 2015-05-09
        • 1970-01-01
        • 1970-01-01
        • 2021-06-05
        相关资源
        最近更新 更多