How to implement Splash Screen in Android, In this tutorial we are going to learn how to add splash screen in an android application. Android splash screen is normally used to show the user some kind of progress before the app loads completely. People use splash screen just to show their app/company logo for a couple of seconds.
An Android app takes some time to start up, especially when the app is first launched on a device. A splash screen may display startup progress to the user or to indicate branding.
I’m taking a simple image and text for displaying on the splash screen.
Table of Contents
Create SplashScreen Project
- Create a new project in Android Studio by navigating to File => New => New Project Application Project and fill required details. (I kept my main activity name as MainActivity.java)
- For welcome Screen, we are creating a separate activity.
Create a layout file for the splash screen
This layout normally contains your app logo or company logo or some text.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/splashbackground" > <ImageView android:id="@+id/Logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:src="@drawable/logo" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:textSize="12dp" android:textColor="#454545" android:gravity="center_horizontal" android:layout_alignParentBottom="true" android:text="www.techjunkgigs.com" /> </RelativeLayout>
Code For Splash Screen
The following code for MainActivity.java activity.
package com.example.jamaley.myapplication; import android.content.Intent; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { private static int TIME_OUT = 5000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent i = new Intent(MainActivity.this, welcome.class); startActivity(i); finish(); } }, TIME_OUT); } }
public void run() { Intent i = new Intent(MainActivity.this, welcome.class); startActivity(i); finish(); }
This method will be executed once the timer is over and start your app welcome screen activity
after that is finish the previous activity
Android Manifest File
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.jamaley.myapplication"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <!-- Splash screen --> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- Welcome activity --> <activity android:name=".welcome"></activity> </application> </manifest>
Run the application, you will see the splash screen for 5 sec and then your welcome screen activity will be launched.
Result
You can Also Check
I hope this tutorial helped you to learn How to implement Splash Screen in Android. To get the latest news and updates follow us on twitter & facebook, subscribe to our YouTube channel. If you have any query then please let us know by using comment.
Basit Ansari says
Hey Jamaley,
I am first time visit on your blog and I love your blog and thanks for sharing amazing articles with us.
Jamaley Hussain says
Hi Basit
I’m glad that you like it.
Thank you for stopping and commenting here keep visiting.
Safeer says
amazing article
Jamaley Hussain says
Hi Safeer
I’m glad that you like it.
Thank you keep visiting.
Anil says
Hey,
Very informative article
Thank you! keep sharing such articles.
Jamaley Hussain says
Hi Anil,
Glad to know that you like the article. Thanks for visiting and commenting here.
Keep Visiting.