Android splash screen VectorDrawable

The issue has to do with API's 21, 22 and 23 for those you need to wrap the drawable around a bitmap. what you need to do is create 2 versions of your drawable layer-list and put one into drawable-v22 and the other in drawable-v24, if these folders dont already exist just create them inside res/ and note that you need to set project view to poject in order to see them (see image below).

for v24 you just use the one you already have:

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

<item

    android:gravity="center"
    android:src="@drawable/splash_screen" >
</item>

</layer-list>

for drawable-v21 you use the following (note that for some reason these drawable wont work on API's higher that 23)

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

<item android:gravity="center">
    <bitmap
        android:gravity="center"
        android:src="@drawable/splash_screen" />
</item>

</layer-list>

android will then take either the first or the second asset depending on the API of the device and then your splashscreen will look great on all devices.

BTW here is the documentation on other customizations you can implement not only on device API but also on screen sizes, resolution and many more.

enter image description here


VectorDrawable defines a static drawable object. Similar to the SVG format, each vector graphic is defined as a tree hierachy, which is made up of path and group objects. Each path contains the geometry of the object's outline and group contains details for transformation.

You can use SDP - a scalable size unit.

An android SDK that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens.

To add sdp to your project (Using Android Studio and Gradle) build.gradle

dependencies {
  implementation 'com.intuit.sdp:sdp-android:1.0.6'
}

Now add sdp instead of dp.

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="@dimen/_300sdp"
    android:height="@dimen/_225sdp"
    android:viewportWidth="512"
    android:viewportHeight="512">

Note - Use AppCompatImageView (With app:srcCompat) instead of ImageView in your layout.

 <android.support.v7.widget.AppCompatImageView //Or androidx.appcompat.widget.AppCompatImageView
    app:srcCompat="@drawable/your_svg"
    />