I'm basically using the following xml's for an Android Splash Screen: Empty activity with windowBackground:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
background_splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/defaultBackground" />
</item>
<item>
<bitmap
android:src="@drawable/logo"
android:tileMode="disabled"
android:gravity="center"/>
</item>
</layer-list>
This works fine as long the logo.png is smaller than the screen size. If the logo.png is bigger than the screen it goes beyond the screen.
I see 3 workarounds, but all have drawbacks:
left/right in <item, but this requires API 23+@drawable/logo for xhdpi, xxhdpi etc. but I'm using Density Split, which would break it when reusing apk's for other devices (apk sites, "Move to new device"-Apps that transfer apks etc.)ImageView, but this has an noticeable delayHow to do it correctly / without drawbacks?
I found no good solution, so I looked at how Google Drive's splashscreen is implemented.
Basically they use a single splash.png with 384x384px and put it in drawable-xhdpi and used the following xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list android:opacity="opaque"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/defaultBackground" />
<item>
<bitmap android:gravity="center" android:src="@drawable/splash" />
</item>
</layer-list>
That seems to look good on all devices (that I tested) and solves my issues (specifically 2). Highly recommended!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With