Android Mobile Tutorials

Android Splash Screen Tutorial – Android Studio 2015

Written by Jana Raj

In this Android Splash Screen Tutorial, we see how to create how to create android splash screen using Android Studio 1.5.

A splash screen is a graphical control element consisting of window containing an image, a logo and the current version of the software. A splash screen usually appears while a game or program is launching.

Many apps like Facebook, twitter, Skype uses splash screen to splash their branding to the user. Now let see how to create such Splash screen using Android Studio.

android splash screen tutorial

Download Source code

[su_button url=”http://linkshrink.net/7iMD5T” target=”blank” style=”flat” background=”#98de48″ center=”yes” icon=”icon: android”]Download Source[/su_button]

Splash.xml

This is the layout for  your splash screen

Note : 

  • Linear Layout – To align your splash screen in a single direction
  • Width and Height – match_parent to fully cover the visible space of the screen
  • Orientation – Your choice
  • Background – Its your Logo
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageView2"
        android:src="@drawable/Logo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center_horizontal" />

</RelativeLayout>

SplashActivity.java

The below code creates a thread and runs it for the specified time. It makes the splash screen i.e Splash.xml will be displayed for some time.

Note : 

  • sleep(3000) defines the time of the splash screen 3000 = 3 Seconds [Official Doc –  sleep(long time) ]
  • start() – to start the thread.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class SplashScreen extends Activity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
 
        Thread timerThread = new Thread(){
            public void run(){
                try{
                    sleep(3000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent intent = new Intent();
                    startActivity(intent);
                }
            }
        };
        timerThread.start();
    }
 
    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }
 
}

MainActivity.java

Create a onCreate method in MainActivity.java and setContentView to the activity_main.xml file.

package com.jana.tech4bros.com.tech4brosblog;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class Main2Activity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

 

AndroidManifest.xml

You should change the SplashActivity as a Launcher Activity to launch it first and then the MainActivity should be defined in the Manifest file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jana.tech4bros.com.tech4brosblog">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
       <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main2"
            android:theme="@style/AppTheme.NoActionBar">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Main2Activity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">

        </activity>
    </application>

</manifest>

 

About the author

Jana Raj

Janarthanan is the founder and Chief Editor of Tech4bros .He is a Student of Computer Science and Engineering ,a full time Geek, part time Blogger and Quarter time Coder. He loves Blogging, Web Designing and making new friends . Google Plus