【问题标题】:Getting Black screen as splash screen on flutter app startup在颤动应用程序启动时将黑屏作为启动画面
【发布时间】:2021-07-09 03:32:50
【问题描述】:

我的 AndroidManifest.xml :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.flutter_application_1">
   <application
        android:label="flutter_application_1"
        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">
            
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <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>
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

我的 launch_background.xml :我给了白色,但还是黑屏

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher" />
    </item> 
</layer-list>

我的style.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
       <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
    <style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
       <item name="android:windowBackground">?android:colorBackground</item>
    </style>
</resources>

res 文件夹:

flutter run --verbose :报告Verbose Report

剩下的一切工作正常,我面临的唯一问题是这个启动/启动屏幕。 请帮我弄清楚。

【问题讨论】:

    标签: android flutter splash-screen


    【解决方案1】:

    检查您的 styles.xml 文件,它应该如下所示:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="LaunchTheme" parent="Theme.AppCompat.NoActionBar">
            <item name="android:windowBackground">@drawable/launch_background</item>
        </style>
      
        <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
            <item name="android:windowBackground">@drawable/launch_background</item>
        </style>
    </resources>
    

    如果仍然没有结果,请尝试在 launch_background.xml 中使用 &lt;item&gt; 属性而不是 &lt;bitmap&gt; 作为 launch_image

    <?xml version="1.0" encoding="utf-8"?>
    <!-- Modify this file to customize your launch splash screen -->
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@android:color/white" />
    
        <item
            android:drawable="@drawable/launch_image"
            android:gravity="center" />
    </layer-list>
    

    【讨论】:

    • 我尝试了你的建议,但仍然没有改变,我更新了我的问题,包括我的“style.xml”文件和“res”文件夹屏幕短。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多