How to make an advanced Splash Screen for your Android App

Standard

Create your splash.xml file some thing like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:id="@+id/TheSplashLayout"
 android:layout_gravity="center"
 >
 <ImageView 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:id="@+id/SplashImageView"
 android:layout_gravity="center" 
 android:src="@drawable/lnxins" 
 >
 </ImageView>
</LinearLayout>

Write your Splash screen java file:

public class SplashScreen extends Activity {
 
 /**
 * The thread to process splash screen events
 */
 private Thread mSplashThread; 

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 // Splash screen view
 setContentView(R.layout.splash);
 
 final SplashScreen sPlashScreen = this; 
 
 // The thread to wait for splash screen events
 mSplashThread = new Thread(){
 @Override
 public void run(){
 try {
 synchronized(this){
 // Wait given period of time or exit on touch
 wait(5000);
 }
 }
 catch(InterruptedException ex){ 
 }

 finish();
 
 // Run next activity
 Intent intent = new Intent();
 intent.setClass(sPlashScreen, MainActivity.class);
 startActivity(intent);
 stop(); 
 }
 };
 
 mSplashThread.start(); 
 }
 
 /**
 * Processes splash screen touch events
 */
 @Override
 public boolean onTouchEvent(MotionEvent evt)
 {
 if(evt.getAction() == MotionEvent.ACTION_DOWN)
 {
 synchronized(mSplashThread){
 mSplashThread.notifyAll();
 }
 }
 return true;
 } 
}

Create apear and disapear animation xml files:

<set xmlns:android="http://schemas.android.com/apk/res/android">
 <alpha
 android:interpolator="@android:anim/accelerate_interpolator"
 android:fromAlpha="0.0" android:toAlpha="1.0"
 android:duration="800"
 />
</set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
 <alpha
 android:interpolator="@android:anim/decelerate_interpolator"
 android:fromAlpha="1.0" android:toAlpha="0.0"
 android:duration="800"
 />
</set>

Add your animation as a style to your style resource file:

<style name="Animations" parent="@android:Animation" />
 <style name="Animations.SplashScreen">
 <item name="android:windowEnterAnimation">@anim/appear</item>
 <item name="android:windowExitAnimation">@anim/disappear</item> 
 </style>
</style>

Add this style to your style resource file for a transparent splash activity:

 <style name="Theme.Transparent" parent="android:Theme">
 <item name="android:windowIsTranslucent">true</item>
 <item name="android:windowBackground">@android:color/transparent</item>
 <item name="android:windowContentOverlay">@null</item>
 <item name="android:windowNoTitle">true</item>
 <item name="android:windowIsFloating">true</item>
 <item name="android:backgroundDimEnabled">false</item>
 <item name="android:windowAnimationStyle">@style/Animations.SplashScreen</item>
 </style>

Add your splash activity to manifest file like this:

<activity 
 android:name="SplashScreen"
 android:theme="@style/Theme.Transparent">
 <intent-filter>
 <action android:name="android.intent.action.MAIN"></action>
 <category android:name="android.intent.category.LAUNCHER"></category>
 </intent-filter>
</activity>

 

Splash Sample

Splash Sample

That’s it…

Leave a Reply

Your email address will not be published. Required fields are marked *