I'm sorry I need to keep asking this as I'm not getting any answers.
In Android Studio you can set a drawable as the splash screen like so:
splash_screen.xml in the drawable folder:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/blue"/>
<item
android:drawable="@mipmap/ic_launcher_foreground"
android:gravity="center"
android:top="201dp"
android:bottom="201dp"
android:right="100dp"
android:left="100dp"/>
</layer-list>
Add SplashTheme to styles.xml:
<style name="SplashTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:background">@drawable/splash_screen</item>
<item name="android:windowAnimationStyle">@null</item>
</style>
SplashActivity class (doesn't have a layout):
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
And finally in Manifest remove the intent-filter from MainActivity and add it to SplashActivity:
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
And that's it. So instead of a drawable how do I add a lottie animation? I know it's possible because I've seen many apps load an animation immediately when opened. I've googled this question and the answers provided are all wrong because they instruct you to add a new launcher activity that contains a layout with the animation that plays it till the end or uses handler.postDelayed
. The goal of the animation is supposed to be showing the user something while the app loads. Why would you intentionally add a delay for the user that's not part of the loading time?