3

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:

  1. Setting left/right in <item, but this requires API 23+
  2. Vary @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.)
  3. Use layout with an ImageView, but this has an noticeable delay

How to do it correctly / without drawbacks?

Tearsdontfalls
  • 767
  • 2
  • 13
  • 32
  • 1
    It is not an answer - can you use vector drawables? – Eugen Martynov Feb 03 '20 at 22:26
  • @EugenMartynov Have not triedyet , but I wanted to support API 17+. Since vectors are only supported natively for API 21+ and API 17-20 devices are usually slow/old I'd think that there would be a noticeable delay for showing logo. – Tearsdontfalls Feb 03 '20 at 23:05

1 Answers1

7

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!

Tearsdontfalls
  • 767
  • 2
  • 13
  • 32