Simplified Coding

  • About
  • Contact Us
  • Advertise
  • Privacy Policy
You are here: Home / Android Application Development / Android Splash Screen Example – Implementing Splash Screen

Android Splash Screen Example – Implementing Splash Screen

September 19, 2018 by Belal Khan 3 Comments

Hi everyone, welcome to another useful tutorial for beginners. So this post will show you an Android Splash Screen Example. An splash screen is a screen that shows up when we launch the app. Splash Screen is very common term and it is required for all the application. The idea behind this is, to show user a welcome screen while your application is loading.

In this android splash screen example we are going to learn how do we implement a splash screen in our application. So let’s begin.

Android Splash Screen Example

For building the Splash Screen the first thing needed is the design of the screen. But as this post is only an example we will not dig much into the designing part. Here I am going to use only a logo that I will display in the center of the screen.

Now let’s just create our android project.

  • Here I have created a new project using an EmptyActivity.
  • Once your project is loaded, first we will design our Splash Screen.

Designing Splash Screen

You can play with the design as much as you want. Here I am just using logo of StackOverflow to create a very quick design. It is having nothing just the logo image on the center.

For designing the Splash Screen we will create a drawable resource file.

  • Right click on the drawable folder and create a new drawable resource file. Here I have created splash_screen.xml.
android splash screen example

Creating Drawable Resource File

  • Here we are going to design our Splash Screen. So inside the file put the following code.

splash_screen.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
 
    <item>
        <color android:color="#ffffff"></color>
    </item>
 
    <item
        android:width="170dp"
        android:height="180dp"
        android:drawable="@drawable/app_logo"
        android:gravity="center_horizontal|center_vertical" />
 
</layer-list>

  • In the above code app_logo is the image file that I have already pasted inside my drawable folder, you need to put your logo that you want in the splash screen.
  • Now we will create a theme that will show this designed screen as the background of our activity.

Creating Splash Theme

  • Open the file res->values->styles.xml and modify it as below.

styles.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<resources>
 
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
 
 
    
    <!-- Android Splash Screen Example -->
    <style name="AppTheme.Launcher" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_screen</item>
    </style>
 
</resources>

  • So we have a theme that will show up our Splash Screen. As you can see for the windowBackground of the theme we have set the splash_screen.xml.

Displaying Splash Screen

Let me first tell you the idea. The splash screen will show up only when the activity is not loaded, once the activity is loaded the splash screen will disappear. That is why we have set the splash screen as the windowBackground, so it will so the splash screen only when the activity is not loaded.

  • To achieve this objective we will change our MainActivity theme with the theme we created. So come inside AndroidManifest.xml and change the theme to App.Launcher, as shown in the below code.

AndroidManifest.xml
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"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.simplifiedcoding.androidsplashscreen">
 
    <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.Launcher">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>

  • Now when we launch the activity it will show the Splash Screen, and when the activity is loaded we will change the theme and then it will display our Activity.
  • So come inside MainActivity.java and change the theme inside the method onCreate().

MainActivity.java
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package net.simplifiedcoding.androidsplashscreen;
 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
 
public class MainActivity extends AppCompatActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
 
        //Setting the AppTheme to display the activity
        setTheme(R.style.AppTheme);
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //then you can do the rest of the activity thing
    }
}

  • Now run the application and you will see your designed splash screen before loading the activity. It may be too quick if your device is very fast.

So that is all for this Android Splash Screen Example friends. I hope you found it helpful. For any kind of question you can leave your comments.

And if you think the post is helpful please share this post with your friends. Thank You 🙂

 

Sharing is Caring:

  • Tweet
  • Share on Tumblr
  • More
  • Pocket
  • Print
  • Email

Related

Filed Under: Android Application Development, Android Beginners

About Belal Khan

I am Belal Khan, I am currently pursuing my MCA. In this blog I write tutorials and articles related to coding, app development, android etc.

Comments

  1. Arpit Kansal says

    October 2, 2018 at 4:54 am

    Instead of modifying android:theme in application tag of manifest file, it should be modified in mainactivity tag.
    If the activity’s tag is modified then one needs to specify setTheme method in every class.

    Reply
    • Mg Kyaing says

      February 8, 2019 at 11:51 am

      Thanks

      Reply
  2. abrar says

    November 4, 2018 at 7:01 am

    Thanks belal for this sample program but i want this splash for some more seconds of time

    Reply

Leave a Reply Cancel reply

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

Search




Download our Android App

Simplified Coding in Google Play

About Me

Belal Khan

Hello I am Belal Khan, founder and owner of Simplified Coding. I am currently pursuing MCA from St. Xavier's College, Ranchi. I love to share my knowledge over Internet.

Connect With Me

Follow @codesimplified
Simplified Coding

Popular Tutorials

  • Android JSON Parsing – Retrieve From MySQL Database
  • Android Login and Registration Tutorial with PHP MySQL
  • Android Volley Tutorial – Fetching JSON Data from URL
  • Android Upload Image to Server using Volley Tutorial
  • Android TabLayout Example using ViewPager and Fragments
  • Retrieve Data From MySQL Database in Android using Volley
  • Firebase Cloud Messaging Tutorial for Android
  • Android Volley Tutorial – User Registration and Login
  • Android Upload Image to Server Using PHP MySQL
  • Android Navigation Drawer Example using Fragments




About Simplified Coding

Simplified Coding is a blog for all the students learning programming. We are providing various tutorials related to programming and application development. You can get various nice and simplified tutorials related to programming, app development, graphics designing and animation. We are trying to make these things simplified and entertaining. We are writing text tutorial and creating video and visual tutorials as well. You can check about the admin of the blog here and check out our sitemap

Quick Links

  • Advertise Here
  • Privacy Policy
  • Disclaimer
  • About
  • Contact Us
  • Write for Us

Categories

Android Advance Android Application Development Android Beginners Android Intermediate Ionic Framework Tutorial JavaScript Kotlin Android Others PHP Advance PHP Tutorial React Native

Copyright © 2017 · Simplified Coding· All rights Reserved. And Our Sitemap.All Logos & Trademark Belongs To Their Respective Owners·

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.