Splashscreen updates for Android 12

Viewed 254

I recently updated my test phone for my app to Android 12. When I go to run my uno-platform app, the splashscreen no longer has my custom image on it. It now has the launcher icon. In doing some reading- this is a change that was done in Android 12. My question is how do I get my splashscreen to once again show my custom image? Will this change also work on Android 11 devices- or is something additional I need to do to handle both cases? Here is my code for my splashscreen- there is one for dark and one for light.

Light Mode Splashscreen(splash_screen.xml in drawable folder):

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <!-- background color -->
    <color android:color="#dedcdc"/>
  </item>
  <item>
    <!-- splash image -->
    <bitmap
        android:src="@drawable/splashscreen"
        android:tileMode="disabled"
        android:gravity="center" />
  </item>
</layer-list>

Dark Mode Splashscreen(splash_screen_night.xml in drawable folder):

<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <!-- background color -->
    <color android:color="#888689"/>
  </item>
  <item>
    <!-- splash image -->
    <bitmap
        android:src="@drawable/splashscreen"
        android:tileMode="disabled"
        android:gravity="center" />
  </item>
</layer-list>

Styles.xml(Light Mode):

<?xml version="1.0" encoding="utf-8" ?>
<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light">

        <!-- This removes the ActionBar -->
        <item name="windowActionBar">false</item>
        <item name="android:windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowNoTitle">true</item>
  
    <!-- Splash Screen -->
    
      <item name="android:windowBackground">@drawable/splash_screen</item>
    
    </style>
  
 
</resources>

(In values-night folder for dark mode)Styles.xml:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
    <style name="AppTheme" parent="Theme.AppCompat">

        <!-- This removes the ActionBar -->
        <item name="windowActionBar">false</item>
        <item name="android:windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowNoTitle">true</item>
  
    <!-- Splash Screen -->
    
      <item name="android:windowBackground">@drawable/splash_screen_night</item>
     
    </style>
  
 
</resources>
1 Answers

Starting Android 12, there is a new Splash Screen API that is replacing the current approach to creating splash screens on Android. To use this new API, you will need to migrate to it using steps described in the Android documentation here.

To support both new and older versions of Android, there is a AndroidX Splash Screen API in AndroidX Core library, but that is not bound in Xamarin version of the library at the time of writing (see the issue here on GitHub). Therefore you need to make sure the code for Android 12 support runs only on A12 and newer for now (while older targets can keep using the approach that worked for you until now).

Related