android splash screen, beautiful splash screen android,  How to create a splash screen in android

How to create a splash screen in android

A splash screen is that activity that welcomes a user when he opens an app. It is the first screen that opens and usually, it is used to inform the user that he is truly in the application he was looking for.

The splash screen creates the first user experience within the app therefore it must attract the user so that the user can get interested to continue using the app. The splash screen must be simple and straightforward to allow the user to understand the app.

For most applications that are popular in the world right now, for example, WhatsApp, the splash screen usually contains the logo of the app and also the account owner or developer of the account.

The splash screen must be minimalist in the contents it is having mostly text and image are enough.

No action or interaction is required from the user in the splash screen since it is a welcoming screen or activity. What is required to do in the splash screen, you should set the delay of the screen to like 3 seconds, and then the app automatically redirects to the screen where the user input is needed, for example, the login screen.

To create a splash screen in android, you will need to follow the steps of creating an activity in the android studio just the normal way and you can follow the steps from this previous article

Click File, then new, followed by activity finally select empty activity

android splash screen, beautiful splash screen android,  How to create a splash screen in android

In the modal that will appear, name it SplashScreen and click next

android splash screen, beautiful splash screen android,  How to create a splash screen in android

Wait for Gradle to finish importing resources

Open the activity_splash_screen.xml and add the contents you want to be visible in the screen. We do recommend a text and an image

The full xml code for splash screen activity is as follows

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    tools:context=".SpashScreen">

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Solutions Space App"

        android:layout_marginTop="200dp"

        android:layout_marginLeft="70dp"

        android:textSize="30dp"

        android:textColor="@color/teal_200"

        />

    <ImageView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_marginLeft="40dp"

        android:src="@drawable/soln"

        />

 

</LinearLayout>

Next move to the SplashActivity.kt and set the delay time to 3 seconds before opening the other activity you want direct the user to

To redirect to MainActivity and delay with 3 seconds

Handler().postDelayed({

            val intent = Intent(this, MainActivity::class.java)

            startActivity(intent)

            finish()

        }, 3000) // 3000 milliseconds

The full SplashScreen activity is as follows

package com.example.firstandroidapp

 

import android.content.Intent

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle

import android.os.Handler

 

class SpashScreen : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_spash_screen)

 

        Handler().postDelayed({

            val intent = Intent(this, MainActivity::class.java)

            startActivity(intent)

            finish()

        }, 3000)

    }

}

Next, you will need to set the splash screen activity as the first activity or the launcher activity and that is done in the android manifest file

The code that sets the splash screen as the launcher activity in android is as below

<activity android:name=".SpashScreen">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

The full code for android manifest is as shown below

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.firstandroidapp">

 

    <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/Theme.FirstAndroidApp">

        <activity android:name=".SpashScreen">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <activity android:name=".RegisterActivty" />

        <activity android:name=".MainActivity">

        </activity>

    </application>

 

    <uses-permission android:name="android.permission.INTERNET" />

 

</manifest>

 

We have discussed how to create a splash screen in android and we have shown to add the delay of 3 seconds and also how to navigate to the next activity.

In summary, to create a splash screen in android, the main steps are

  • Creating the splash screen activity
  • Add text view and image view in the XML file
  • Add the delay time of 3 seconds or any other value in the splash activity using kotlin
  • Using intents to direct from splash screen to the next activity after 3 seconds
  • Setting the splash screen as the launcher activity using the manifest file

One thing to note is that you can create the design you wish to for the splash screen, this article is here to guide you on the basic steps to create a splash screen in android