Search code examples
androidxmlandroid-studioandroid-animationdrawable

Android 12 Splash Screen will not animate


I am using the newly released Splash Screen API for Android 12, however the animatable vector will not animate. The icon that shows is just a snapshot of the drawable.

I've added this line of code into my themes.xml file:

<item name="android:windowSplashScreenAnimatedIcon">@drawable/sample</item>

sample.xml

<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:aapt="http://schemas.android.com/aapt" >
    <aapt:attr name="android:drawable">
        <vector
            android:height="64dp"
            android:width="64dp"
            android:viewportHeight="600"
            android:viewportWidth="600" >
            <group
                android:name="rotationGroup"
                android:pivotX="300.0"
                android:pivotY="300.0"
                android:rotation="45.0" >
                <path
                    android:name="v"
                    android:fillColor="#000000"
                    android:pathData="M300,70 l 0,-70 70,70 0,0 -70,70z" />
            </group>
        </vector>
    </aapt:attr>

    <target android:name="rotationGroup"> *
        <aapt:attr name="android:animation">
            <objectAnimator
                android:duration="6000"
                android:propertyName="rotation"
                android:valueFrom="0"
                android:valueTo="360" />
        </aapt:attr>
    </target>

    <target android:name="v" >
        <aapt:attr name="android:animation">
            <set>
                <objectAnimator
                    android:duration="3000"
                    android:propertyName="pathData"
                    android:valueFrom="M300,70 l 0,-70 70,70 0,0 -70,70z"
                    android:valueTo="M300,70 l 0,-70 70,0  0,140 -70,0 z"
                    android:valueType="pathType"/>
            </set>
        </aapt:attr>
    </target>
</animated-vector>
 

MainActivity.java

package com.example.simplesplashscreen;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Solution

  • You also need to provide the duration:

    If you use the platform API (Android 12+):

    <item name="android:windowSplashScreenAnimationDuration">3000</item>
    

    If you use the core-splashscreen library:

    <item name="windowSplashScreenAnimationDuration">3000</item>
    

    Note that the animated vector only works on Android 12+