I am seeing a weird issue with a new app that I am starting. I am utilizing the new Android 12 splash screen API to create my splash screen and I followed the guide provided by Google to do so. I included core-splashscreen in my project to provide compatibility with older versions of Android OS. When I run the app, I see the splash screen as expected on older OS versions like API 30, but when I run it on API 31, the splash screen icon that I provide is not displayed. The background color that I specify is displayed, but the icon is not there at all. I have tried this with a drawable asset as well as a mipmap and nothing is working. I am stumped as every tutorial I find shows the same steps I have followed and screenshots of their working splash screens, but I am not having any luck.
For context here is my splash screen style definition for v31:
<style name="Theme.Splash" parent="Theme.SplashScreen">
<item name="android:windowSplashScreenBackground">@color/orange_7A</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_foreground</item>
<item name="postSplashScreenTheme">@style/Theme.App</item>
</style>
I have an identical style for all other OS versions except I'm using "windowSplashScreenAnimatedIcon" instead of "android:windowSplashScreenAnimatedIcon". I have tried v31 with and without the "android:" in front of the item names and neither work. Here is my MainActivity.kt:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
setContent {
MyVeevaTheme {
Login()
}
}
}
I am also setting the "android:theme" property to my splash style in my AndroidManifest.xml. I know the splash style is being applied because it honors the background color, but it is not showing the icon for some reason even though the icon shows fine for older OS versions. Thanks in advance for any help you can give.
Just in case for who faces the issue of the SplashScreen API not always displaying the icon in API 33 and higher, add this to your styles.xml:
<item name="android:windowSplashScreenBehavior"tools:targetApi="33">icon_preferred</item>
Reference from Android Docs:
You can use windowSplashScreenBehavior to specify whether your app always displays the icon on the splash screen in Android 13 and higher. The default value is 0, which displays the icon on the splash screen if the launching activity sets the splashScreenStyle to SPLASH_SCREEN_STYLE_ICON, or follows the system behavior if the launching activity doesn't specify a style. If you prefer to never display an empty splash screen and always want the animated icon to be displayed, set this to the value icon_preferred.
It is intended to hide the icon when starting the app from a notification or from another app other than the Launcher. So just use the above styles attribute to force it to always show the icon.
In case you have a separate file for API 31 and above,
values-v31/styles.xml
, omit the `tools' attribute.
<item name="android:windowSplashScreenBehavior">icon_preferred</item>