Splash Screen in Android Tutorial with Example

Hey Technoz! Hope you are doing great. We have seen many apps in which displays a splash screen at the starting of app for few seconds. So, in this tutorial, we are going to learn how to implement the splash screen in android app. Actually, it is a very easy and quick task. So lets start.

Build the splash screen in android app

Create a new android project or you can continue with your existing one. At first, we need to design our splash screen layout. We will need both java and xml file for this task. So instead of creating only xml file, create a new activity SplashScreenActivity and go to its layout file activity_splash_screen.xml. Write the following code in it.

We have put a simple view above to get splash screen in android app. The parent is Relativelayout in which we put the ImageView for app icon, TextView for app name and ProgressBar to show there is an ongoing progress on opening the app. we are covering these three elements in LinearLayout. A bottom line showing a copyright text, is put with alignParentBottom attribute as true.

Prepare the backend

Now, we will do a little work in java file. So, come to SplashScreenActivity.java and write the following code in it.

In above code, we will let this activity (splash screen) run for 3 seconds and then will close and finish this activity and switches to the MainActivity. We have used Handler class for this task. the method postDelayed() performs the task which is intended to do after the completion of delay. We write our Intent code in that method which will switch the user to another activity after finishing timer. The second argument passed in postDelayed()  method is the time (in milliseconds) which is currently 3000. Thus the splash screen in android will run, in this case, for 3 seconds. You can change the time period according to your requirements.

Now we will move to our AndroidManifest.xml file. Make the SplashScreenActivity as a Launcher Activity and declare MainActivity as an ordinary activity. We don’t need any special permissions for this task, so no need to include any of them, in Manifest. You can refer the below code.

That’s it. We have now set up everything to include a splash screen in android app. Try to run the app now. You should be able to see the splash screen running for 3 seconds as in below screenshot.

Splash Screen in Android Tutorial with Example

In above screen, a splash screen is running with a top action bar. If you are okay with it, then you are done. But if you want to remove the action bar, you have to follow some steps below.

Removing an Action bar

If you are using an AppCompat theme, then you need to create a custom theme for your SplashScreenActivity. In order to create a custom theme, go to res->values->styles.xml and paste the following code snippet below your existing code.

Now, you need to assign this theme to your activity in AndroidManifest.xml. Thus, open the manifest file and add an attribute android:theme="@style/myTheme". So, the activity code will look like

You are done. Now try running your application with the new updated code and you will see a splash screen in android app running in a full screen mode as shown below.

Splash Screen in Android Tutorial with Example

Finally we have completed with our tutorial to add splash screen in android app. Hope you like it. If you have any queries, feel free to ask in comment section below.

Download Source Code

If you want to jump directly to the source code, you can download it for free using the below link.

Please subscribe to our newsletter to catch such more knowledgeable and understanding tutorials. 🙂

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.