I cannot change the default flutter icon in splash screen to image of my choosing in flutter

Viewed 1291

My launch_background.xml

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

My launch_background.xml in drawable-v21

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

My android manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.my_app">
    <uses-permission android:name="android.permission.INTERNET" />
   <application
        android:label="my_app"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:theme="@style/LaunchTheme"
            android:exported="true"
            android:launchMode="singleTop"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <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 -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
    
</manifest>

I can change background color, but the image is always the android:icon="@mipmap/ic_launcher">. No matter what I do (on android).

3 Answers

The source of the problem is that you need to set <item name="android:windowSplashScreenAnimatedIcon">@drawable/...</item> in your values-v31/styles.xml file. However, flutter_native_splash 2.1.0 just added new configuration parameters for setting the icon for the splash screen icon in Android 12 automatically:

  android_12:
    # The image parameter sets the splash screen icon image.  If this parameter is not specified,
    # the app's launcher icon will be used instead.
    # Please note that the splash screen will be clipped to a circle on the center of the screen.
    # App icon with an icon background: This should be 960×960 pixels, and fit within a circle
    # 640 pixels in diameter.
    # App icon without an icon background: This should be 1152×1152 pixels, and fit within a circle
    # 768 pixels in diameter.
    #image: assets/android12splash.png

    # App icon background color.
    #icon_background_color: "#111111"

    # The image_dark parameter and icon_background_color_dark set the image and icon background
    # color when the device is in dark mode. If they are not specified, the app will use the
    # parameters from above.
    #image_dark: assets/android12splash-invert.png
    #icon_background_color_dark: "#eeeeee"

Full disclosure: I maintain this package.

Use flutter native splash, as it gives you some useful and very quick way to handle your splash screen.

At first, import the package, then under the dev dependencies in your pubspec.ymal, add your settings like that:

    flutter_native_splash: 
      color: "#ffffff" // the background color
      image: assets/images/your_image.png // here is your image path
      fullscreen: true
      android: true // true by default
      ios: false    // if you want to generate for Android only
      web: false    

then run this command inside your project directory

flutter pub run flutter_native_splash:create

Among other things, trying to solve the issue I tried using flutter_native_splash. It still shows the icon.

When I remove the ic_launcher.png and android:icon="@mipmap/ic_launcher" from android manifest I get this:

the image with ic_launcher removed

It seems that somehow it is used in the launchscreen no matter what.

I suspect that image might be under the background color.

Related