android上的flutter闪屏跳转

ali*_*awi 4 flutter flutter-layout

我想在颤振中实现我的启动画面。正如这里提到的,我在styles.xml文件中创建了我的 splashScreen 主题并放置了以下代码:

<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
    <item name="android:windowBackground">@drawable/launch_background</item>
</style>
Run Code Online (Sandbox Code Playgroud)

launch_background文件中我把这些代码:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/black" />
<item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/ic_splash" />
</item>
Run Code Online (Sandbox Code Playgroud)

我启动了该应用程序,在加载背景后,我遇到了居中徽标图像的“跳跃”。我该如何解决这个跳跃?

J. *_*Saw 8

对于仍然有此问题的任何人,GitHub 上的解决方案似乎不起作用:

在您的主要 AndroidManifest.xml 文件中,您可能将这些行作为上述 GitHub 答案中的解决方案提供:

<meta-data
    android:name="io.flutter.embedding.android.SplashScreenDrawable"
    android:resource="@drawable/launch_background" />
Run Code Online (Sandbox Code Playgroud)

您可能将这些行放在“flutterEmbedding”元数据标签旁边的底部。如果这样做,请将它们放在<activity>标签中,如本示例所示:

<application
        android:name="io.flutter.app.FlutterApplication"
        android:label="flutter_launch_new"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- HERE -->
            <meta-data
                android:name="io.flutter.embedding.android.SplashScreenDrawable"
                android:resource="@drawable/launch_background" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <!-- NOT HERE -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
Run Code Online (Sandbox Code Playgroud)


ali*_*awi 5

找到这个解决方案后,我通过将以下代码放入其中LaunchTheme(在styles.xml文件中)解决了我的问题:

<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">

    <item name="android:windowBackground">@drawable/launch_background</item>

    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)