Flutter

Flutter黑屏问题,Android启动页和Flutter启动

2020-04-11  本文已影响0人  圈圈猫

在android手机上打开flutter应用的时候,首先会进入到原生的Activity,我们在AndroidManifest.xml中的activity会添加theme,theme会设置背景

<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">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
</activity>

1、我们的styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <!-- Show a splash screen on the activity. Automatically removed when
             Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:statusBarColor">#ffffff</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowIsTranslucent">false</item>
        <item name="android:windowNoTitle">true</item>
    </style>

2、在打开Flutter对应的AndroidManifest.xml中的activity标签内添加如下两条

<meta-data
    android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
    android:value="true" />
<meta-data
    android:name="io.flutter.embedding.android.SplashScreenDrawable"
    android:resource="@drawable/launch_background" />

3、打包测试,从启动的原生背景过渡到flutter的启动图就不会黑屏了,测试发现低端手机依旧会出现黑屏现象,中高端不存在黑屏现象

上一篇 下一篇

猜你喜欢

热点阅读