
Splash Screen With Transition Animation In Android Studio.Splash Screens in android are usually used to show the progress before your application loads completely.Some people uses Splash Screen to show their Company Logo for few seconds before app loads.In our this tutorial we are going to make a splash screen with transition animation in android studio.In this project we will show our company logo for few seconds before our application gets loads completely.So lets start..
YouTube Tutorial
Creating New Project (Splash Screen With Transition Animation In Android Studio)
- Create a new project in Android Studio File–>New–>New Project.
- Enter Application Name, Package Name, Select Empty Activity and click on finish.
Animation Part
- Create a Android Resource Directory under res folder (rec–>new–>Android Resource Directory).
- Name it anim.
- Under this folder (anim) create a Animation Resource File (anim–>new–>Animation Resource File).
- Name it mysplashanimation.xml.
- Following are animation code for our splash screen.
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="2000"> </alpha> |
Create New Class and Layout
- Create a new .java (SplashActivity.java) class for Splash Screen in your package and Layout (activity_splash.xml).
Layout Activity (activity_splash.xml)
- This layout normally contains our app logo or company logo or what ever design we want to show at the beginning of app.
- You can add your logo in ImageView Source.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.androidcodefinder.splashscreendemo.MainActivity" android:background="@color/backgroundColor"> <ImageView android:id="@+id/logo" android:src="@mipmap/splash" android:layout_width="120dp" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> |
SplashActivity.java
- In this class we have used handler which used to wait for specific time and once the timer is out we launched main activity.
- Also we are doing animation with screen which is fading in.
- Code for activity –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
package com.androidcodefinder.splashscreendemo; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; /** * Created by Sumeet Jain on 23-06-2018. */ public class SplashActivity extends AppCompatActivity { private ImageView logo; private static int splashTimeOut=5000; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); logo=(ImageView)findViewById(R.id.logo); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent i = new Intent(SplashActivity.this,MainActivity.class); startActivity(i); finish(); } },splashTimeOut); Animation myanim = AnimationUtils.loadAnimation(this,R.anim.mysplashanimation); logo.startAnimation(myanim); } } |
AndroidManifest.xml File
- Open your your AndroidManifest.xml file and make your splash screen activity as Launcher activity.
- Also change the theme of our SplashActivity.java file to NoActionBar.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.androidcodefinder.splashscreendemo"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> </activity> <activity android:name=".SplashActivity" android:theme="@style/Theme.AppCompat.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
Now we will run our app and we will see splash screen for 5 sec with fade in animation then our main activity will be launched.
Download Complete Project
Splash Screen With Transition Animation In Android Studio Complete Project
Subscribe To Our YouTube Channel
Like Us On Facebook
This example have two issues, because you create the new Handler() as you do here, you will not have the possibility to cancel it. Not cancel it will introduce two bugs. Fist bug is that if you close the app before the splash screen is finished the app will open itself again. The second bug is that if you rotate the screens you will create additional handlers each starting the MainActivity when it times out.