How to implement Android Splash Screen – Step by Step

Using splash screen is very useful for branding. You can use your company’s name to be displayed on the launching of your app. In this article, I will tell you how you can make a simple splash screen app in the Android studio.

Related

  1. How to convert website into android app in android studio-step by step
  2. What is android activity
  3. How to use Listview in android studio step by step? android tutorial
  4. How to use the button in the android studio?
  5. brief overview of project files in android studio
  6. Basic overview of android studio (Hello world)

Steps to create splash screen

  • Create project with empty activity

Create a new Android project in the android studio. Give any name to this project. I gave Splash_screen.

splash screen android tutorial

In this example, I have highlighted basic activity but you can create Empty Activity also. Give any name to the second activity. I gave Splash.

  • Edit activity_splash.xml

Now in this file you can you can change the background image, add Textview etc. This file will decide what will be displayed on the launching of the app. You can say this is our splash screen. I have changed the background with an image. You can copy and paste the code from below. Just change background png file with your own png image. Just copy and paste the image in the drawable folder.

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background=”@drawable/bacc”
tools:context=”.Splash” >

</RelativeLayout>

  • Edit Splash.java

    In this file, we will write some code which will be executed at starting of the app. First of all, create a Thread class object and implement run() method inside the body of Thread class. We want this to be shown for a few seconds, right? In this case sleep() method will help us. We can pass milliseconds into sleep() method as arguments. After sleeping for some seconds we can tell the compiler to jump into MainActivity.java. So we will use Intent class to tell the compiler where to go after sleeping for some seconds. See Splash.java code below.

    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    
    public class Splash extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    
    Thread thread = new Thread(){
    public void run(){
    try {
    sleep(3000);
    Intent intent = new Intent(Splash.this,MainActivity.class);
    startActivity(intent);
    finish();
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    
    }
    
    };
    
    thread.start();
    
    }
    }

     

    Edit AndroidManifest.xml

    In this file, we can decide which activity should be LAUNCHER. In here we have two activities. One is .Splash and other is .MainActivity . We want .splash activity to be our LAUNCHER. So just interchange the positions of  .MainActivity and  .Splash. Your AndroidManifest.xml file will look like below code.

    [Code language = “xml”]

    
    

     

     

    [/code]

    SUMMERY

    This is all about building an app with splash screen. You can use this class in your existing project also.For any query, leave comment below.

Leave a Reply

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