Android Tutorial

Software Setup and Configuration

Android Studio

File Structure

Components

Core Topics

Layout

View

Button

Intent and Intent Filters

Toast

RecyclerView

Fragments

Adapters

Other UI Component

Image Loading Libraries

Date and Time

Material Design

Bars

Working with Google Maps

Chart

Animation

Database

Advance Android

Jetpack

Architecture

App Publish

App Monetization

How to Create an Animated Splash Screen in Android?

Creating an animated splash screen can greatly enhance the user experience of your app. Here's how you can create an animated splash screen in Android:

1. Setup the Splash Activity Layout:

First, create a new layout XML file for the splash screen, e.g., activity_splash.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/your_background_color">

    <!-- Logo or any other drawable you want to animate -->
    <ImageView
        android:id="@+id/imageViewLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/your_logo_drawable" />

</RelativeLayout>

2. Setup Splash Activity:

Create a new SplashActivity.java or SplashActivity.kt:

class SplashActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)

        val imageView: ImageView = findViewById(R.id.imageViewLogo)

        // Use an Animation or Animator to animate the logo or any other UI element.
        // Here's an example using Animation:
        val fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_in)
        imageView.startAnimation(fadeInAnimation)

        // Set a delay for the splash screen
        Handler(Looper.getMainLooper()).postDelayed({
            startActivity(Intent(this, MainActivity::class.java))
            finish()
        }, 3000) // 3 seconds
    }
}

3. Create Animation:

In the res directory, create an anim folder (if it doesn't exist). Inside this folder, create an XML animation file, e.g., fade_in.xml:

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1500"
    android:fromAlpha="0.0"
    android:toAlpha="1.0" />

4. Update AndroidManifest.xml:

Set SplashActivity as the launcher activity:

<activity
    android:name=".SplashActivity"
    android:theme="@style/Theme.AppCompat.NoActionBar"> <!-- Optional: Hide ActionBar for the splash -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

<!-- Your main activity -->
<activity android:name=".MainActivity" />

5. Additional Notes:

  • Avoid making the splash screen too long, as users generally want to access the app content quickly.
  • You can use Android's Animator API for more complex animations.
  • Instead of a simple fade-in, you can combine multiple animations like scale, rotate, translate, etc.
  • Consider using third-party libraries like Lottie for complex animations.

Now, when you start your app, the animated splash screen will appear before transitioning to the main activity.

  1. Create splash screen animation in Android Studio:

    • Description: Develop a splash screen with a basic animation to provide a visually appealing introduction to your Android app.
    • Code:
      <!-- res/anim/splash_animation.xml -->
      <set xmlns:android="http://schemas.android.com/apk/res/android">
          <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000"/>
      </set>
      
  2. Animated launch screen for Android app:

    • Description: Enhance the launch experience by incorporating animations into the app's initial screen.
    • Code:
      // MainActivity.java
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      
          Animation splashAnimation = AnimationUtils.loadAnimation(this, R.anim.splash_animation);
          findViewById(R.id.logoImageView).startAnimation(splashAnimation);
      }
      
  3. Splash screen transition animation Android:

    • Description: Implement a transition animation for the splash screen, creating a smooth and visually appealing effect.
    • Code:
      // MainActivity.java
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      
          Animation slideUpAnimation = AnimationUtils.loadAnimation(this, R.anim.slide_up_animation);
          findViewById(R.id.logoImageView).startAnimation(slideUpAnimation);
      }