Skip to main content

Android - Simple Splash Screen

Operating System


In this tutorial we will try to create a Simple Splash Screen Using Android. Android is most commonly comes installed on a variety of smartphones and tablets, and even in TV. Android is an open source so that developer find it easy to develop and expand new features. So let's do the coding...

Getting Started:

First you will have to download & install the Android Development IDE (Android Studio or Eclipse). Android Studio is an open source development feel free to develop your things.

Here's the link for the Android Studio https://developer.android.com/studio/index.html.

Layout Design

We will now create the design for the application, first locate the activity_main.xml and click text to view the script. Then copy and paste the code below.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context="com.razormist.simplesplashscreen.MainActivity">
  8.  
  9. <TextView
  10. android:id="@+id/tv_loading"
  11. android:layout_height="wrap_content"
  12. android:layout_width="wrap_content"
  13. android:text="LOADING"
  14. android:layout_centerInParent="true"
  15. android:layout_above="@+id/progressBar"
  16. android:textSize="50sp"/>
  17.  
  18. <ProgressBar
  19. android:id="@+id/progressBar"
  20. style="@android:style/Widget.DeviceDefault.Light.ProgressBar.Horizontal"
  21. android:layout_width="match_parent"
  22. android:layout_height="wrap_content"
  23. android:progress="0"
  24. android:layout_centerVertical="true"
  25. android:layout_alignParentLeft="true"
  26. android:layout_alignParentStart="true" />
  27. </RelativeLayout>

Android Manifest File

The Android Manifest file provides essential information about your app to the Android system in which the system must required before running the code.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.razormist.simplesplashscreen">
  4.  
  5. <application
  6. android:allowBackup="true"
  7. android:icon="@mipmap/ic_launcher"
  8. android:label="@string/app_name"
  9. android:roundIcon="@mipmap/ic_launcher_round"
  10. android:supportsRtl="true"
  11. android:theme="@style/AppTheme">
  12. <activity android:name=".MainActivity"
  13. android:configChanges="orientation"
  14. android:screenOrientation="portrait">
  15. <intent-filter>
  16. <action android:name="android.intent.action.MAIN" />
  17.  
  18. <category android:name="android.intent.category.LAUNCHER" />
  19. </intent-filter>
  20. </activity>
  21. </application>
  22.  
  23. </manifest>

The Main Function

This code contains the main function of the application. This code will start running the progress bar to it target point and will load the new page at the same time. To create first locate your java file and open it, then write these block of codes.

  1. package com.razormist.simplesplashscreen;
  2.  
  3. import android.os.Handler;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.widget.ProgressBar;
  7. import android.widget.TextView;
  8.  
  9. public class MainActivity extends AppCompatActivity {
  10. ProgressBar progressBar;
  11. TextView loading;
  12.  
  13. int progress = 0;
  14. Handler h = new Handler();
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. progressBar = (ProgressBar)findViewById(R.id.progressBar);
  20. loading = (TextView)findViewById(R.id.tv_loading);
  21.  
  22. new Thread(new Runnable() {
  23. @Override
  24. public void run() {
  25. for(int i = 0; i < 5; i++){
  26. progress += 20;
  27. h.post(new Runnable() {
  28. @Override
  29. public void run() {
  30. progressBar.setProgress(progress);
  31. if(progress == progressBar.getMax()){
  32. progressBar.setVisibility(4);
  33. loading.setText("WELCOME");
  34. }
  35. }
  36. });
  37. try{
  38. Thread.sleep(3000);
  39.  
  40. }
  41. }
  42. }
  43. }).start();
  44. }
  45. }

Try to run the app and see if it worked.

There you have it we create a Simple Splash Screen using Android. I hope that this tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.