Sindu Potha

Sindu Potha was created by us who wish to enjoy Sri Lankan songs.

How to create Splash Screen? Add Welcome Screen to Your App

How to create Splash Screen? Add Welcome Screen to Your App
How to create Splash Screen? Add Welcome Screen to Your App

Table of Contents

How to create Splash Screen?

Add Welcome Screen to Your App. This is the right way to add a splash screen for your android app. previously we discussed,

Create Splash Screen – Android Studio

How to create Splash Screen? Add Welcome Screen to Your App

1. First you need to create a new Empty Activity. java > (right-click) New > Activity > Empty Activity > Name Activity “WelcomeScreen” .

2. Now visit Android Mainfest.xml and change the WelcomeScreen Activity to Main Activity.

<activity android:name=".WelcomeScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

3. Now go to activity_welcome_screen.xml and add your app logo.

To add images you have to copy the image file and paste it into the drawable file in Android Studio.

<ImageView
android:id="@+id/imageView"
android:layout_width="140dp"
android:layout_height="141dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/techedutricks_logo"
/>

4. Now go to WelcomeScreen.java and add the following code.

Now all done your splash screen will show 5 seconds. After that, your main activity will open.

Full Codes For the Splash Screen.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.techedutricks.techedutricks">

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

<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.TechEduTricks">

<activity android:name=".MainActivity">

</activity>
<activity android:name=".WelcomeScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

activity_welcome_screen.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".WelcomeScreen">

<ImageView
android:id="@+id/imageView"
android:layout_width="140dp"
android:layout_height="141dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/techedutricks_logo"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

WelcomeScreen.java

package com.techedutricks.techedutricks;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class WelcomeScreen extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome_screen);

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new
Intent(WelcomeScreen.this,MainActivity.class);
startActivity(i);
finish();
}
}, 5000);

}
}

Leave a Comment

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

Scroll to Top