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
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:
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>
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 } }
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" />
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" />
Animator
API for more complex animations.Now, when you start your app, the animated splash screen will appear before transitioning to the main activity.
Create splash screen animation in Android Studio:
<!-- 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>
Animated launch screen for Android app:
// 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); }
Splash screen transition animation Android:
// 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); }