Creating a splash screen in an Android app involves designing a screen that is displayed briefly when the app is launched, providing a visual transition before the main content appears. Here’s a step-by-step guide on how to create a simple splash screen in an Android app:
- Create Layout File: First, create a layout XML file for your splash screen. This file will define the UI elements displayed on the splash screen. Create a new XML file in your
res/layout
directory (e.g.,activity_splash.xml
):
<?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=".Splash">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"></ImageView>
</RelativeLayout>
Splash.kt
package com.androindian.harikaproject
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
class Splash : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
Handler().postDelayed(Runnable {
var intent=Intent(this,MainActivity::class.java)
startActivity(intent)
},5000)
}
}