Skip to content

Niyander Tech

Learn with fun

Menu
  • Home
  • Categories
    • Android
    • Alpine.js Components
    • Genshin Impact News
    • Jobs and Internship
    • Coursera Hub
  • Our Policies
    • Privacy Policy
    • Terms and Conditions
    • Contact Us
Menu
Splash Screen in Android

Splash Screen in Android

Posted on December 4, 2020September 6, 2024 by Niyander

How to Create a Splash Screen in Android Studio

In this blog Post, I’m going to guide you on how to create a splash screen in Android Studio. A splash screen is a screen that appears when you open an app, typically displaying a logo or a brand name before the main content loads. This is a great way to enhance the user experience and provide a professional touch to your app.

 

Step-by-Step Guide to Create a Splash Screen

 

Step 1: Create a New Project

  • First, start by creating a new Android project in Android Studio. Name the project as Splash and choose an Empty Activity.

Step 2: Add Your Logo to the Project

  • Copy your logo image into the drawable folder.
  • Ensure the image is in either .png or .jpg format to be compatible with Android Studio.

Step 3: Create a Splash Activity

  • Navigate to the java folder under com.example.splash.
  • Right-click on the package, and select New > Activity > Empty Activity.
  • Name the activity SplashActivity.

Step 4: Modify the AndroidManifest.xml

To make the splash screen the launcher activity, you need to adjust the AndroidManifest.xml file. Replace the launcher activity with the new SplashActivity.

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

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

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

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

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
</manifest>

In the above code, the SplashActivity is now set as the launcher activity, which will be displayed first when the app starts.

 

Step 5: Design the Splash Screen Layout

Now, let’s design the layout for the splash screen by creating the activity_splash.xml file in the res/layout folder. Here’s the code for the layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".SplashActivity">

<ImageView
android:id="@+id/imageView"
android:layout_width="203dp"
android:layout_height="207dp"
android:layout_centerInParent="true"
app:srcCompat="@drawable/logos"
tools:srcCompat="@drawable/logos" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginBottom="136dp"
android:fontFamily="@font/artifika"
android:text="Animi World"
android:textSize="36sp"
android:textStyle="bold" />
</RelativeLayout>

 

This layout includes:

  • An ImageView for the logo.
  • A TextView for the brand name.

Step 6: Add Logic to the Splash Screen

Now let’s write the logic for the splash screen in SplashActivity.java. The goal is to display the splash screen for 3.5 seconds before transitioning to the main activity.

package com.example.splash;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
getSupportActionBar().hide(); // Hides the ActionBar for the splash screen

// Creating a new thread to handle the delay
Thread thread = new Thread() {
public void run() {
try {
// Delay of 3.5 seconds (3500 milliseconds)
sleep(3500);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// Start the MainActivity after the splash screen
Intent openMain = new Intent(SplashActivity.this, MainActivity.class);
startActivity(openMain);
finish(); // Close the splash screen so that the user cannot return to it
}
}
};
thread.start();
}
}

 

In this code:

  • A thread is used to pause the app for 3.5 seconds.
  • After the delay, the app transitions to MainActivity.

Step 7: Run the App

Now, build and run your app. You should see the splash screen with your logo and brand name for 3.5 seconds before it navigates to the main activity.

 

 

Category: Android

Post navigation

← Add Two Number Program app in Android Studio
Quotes app using android Studio →

Leave a Reply Cancel reply

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

About

Greetings, Hey i am Niyander, and I hail from India, we strive to impart knowledge and offer assistance to those in need.

  • Alpine.js Components
  • Android
  • Bootstrap
  • Coursera Hub
  • Genshin Impact News
  • Jobs and Internship
  • Uncategorized

Hot Topics

  • Microsoft Azure Security Engineer Associate (AZ-500) Quiz Answers + Honest Review
  • Capstone and Practice Exam (AZ-500) Quiz Answers + Review
  • Manage Security Operations Quiz Answers + Review
  • Secure Your Data at Rest Quiz Answers + Review
© 2025 Niyander Tech | Powered by Minimalist Blog WordPress Theme