banner



How To Give Launch Screen A Customed Class File For Animation

Prerequisites: How to Create a Splash Screen in Android using Kotlin?

Android Splash Screen is the offset screen visible to the user when the application'due south launched. Splash Screen is the user'south beginning experience with the application that's why it is considered to be i of the most vital screens in the application. It is used to brandish some information about the company logo, visitor proper name, etc. Nosotros can as well add some animations to the Splash screen likewise. In this article, nosotros will exist making an animated Splash Screen Using Kotlin.A sample GIF is given beneath to get an idea about what we are going to do in this article.

Animated Splash Screen in Android

Steps to Create an Animated Splash Screen

Pace 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.

Stride 2: Create an animation file

To create an blitheness file in android studio delight follow the given instructions carefully. Go to the app > res > right-click > New > Android Resources Directory.

Animated Splash Screen in Android

Then name the directory name as anim. And and then click on OK.

Animated Splash Screen in Android

Become to the anim > correct-click > New > Animation Resources File

Animated Splash Screen in Android

And name the file proper noun as side_slide and click on OK.

Animated Splash Screen in Android

Now add this lawmaking to the animated XML file. Below is the code for the side_slide.xml file.

XML

<? xml version = "one.0" encoding = "utf-eight" ?>

< set

< interpret

android:duration = "1500"

android:fromXDelta = "-50%"

android:fromYDelta = "0%" />

< blastoff

android:duration = "1500"

android:fromAlpha = "0.1"

android:toAlpha = "1.0" />

</ prepare >

Step 3: Create some other activity

Go to app > java > first package name > correct-click > New > Activity > Empty Activity and create another activeness and named it equally SplashScreen. Edit the activity_splash_screen.xml file and add image, text in the splash screen every bit per the requirement. Here we are calculation an prototype to the splash screen. Beneath is the code for the activity_splash_screen.xml file.

XML

<? xml version = "i.0" encoding = "utf-viii" ?>

< androidx.constraintlayout.widget.ConstraintLayout

android:layout_width = "match_parent"

android:layout_height = "match_parent"

android:background = "#fff"

tools:context = ".SplashScreen" >

< ImageView

android:id = "@+id/SplashScreenImage"

android:layout_width = "300dp"

android:layout_height = "200dp"

android:src = "@drawable/geeksforgeeks"

app:layout_constraintBottom_toBottomOf = "parent"

app:layout_constraintLeft_toLeftOf = "parent"

app:layout_constraintRight_toRightOf = "parent"

app:layout_constraintTop_toTopOf = "parent" />

</ androidx.constraintlayout.widget.ConstraintLayout >

Go to the SplashScreen.kt file, and refer to the following lawmaking. Below is the code for the SplashScreen.kt file. Comments are added inside the lawmaking to empathize the code in more item.

Kotlin

import android.content.Intent

import android.os.Bundle

import android.bone.Handler

import android.view.WindowManager

import android.view.animation.AnimationUtils

import android.widget.ImageView

import androidx.appcompat.app.AppCompatActivity

@Suppress ( "DEPRECATION" )

course SplashScreen : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super .onCreate(savedInstanceState)

setContentView(R.layout.activity_splash_screen)

window.setFlags(

WindowManager.LayoutParams.FLAG_FULLSCREEN,

WindowManager.LayoutParams.FLAG_FULLSCREEN

)

val backgroundImage: ImageView = findViewById(R.id.SplashScreenImage)

val slideAnimation = AnimationUtils.loadAnimation( this , R.anim.side_slide)

backgroundImage.startAnimation(slideAnimation)

Handler().postDelayed({

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

startActivity(intent)

stop()

}, 3000 )

}

}

Step 4: Working with the AndroidManifest.xml file

Go to the AndroidManifest.xml file and add the following code in the Splash Screen Activity. This is used to hide the condition bar or action bar.

android:theme="@mode/Theme.AppCompat.Low-cal.NoActionBar"

Also, add <intent-filter> inside the Splash Screen Action to make this activeness as the starting activity. So whenever the app will execute the user tin see the splash screen at the start. Below is the consummate lawmaking for the AndroidManifest.xml file.

XML

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

packet = "com.example.animatedsplashscreen" >

< awarding

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/AppTheme" >

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

< action

android:name = ".SplashScreen"

android:theme = "@mode/Theme.AppCompat.Calorie-free.NoActionBar" >

< intent-filter >

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

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

</ intent-filter >

</ activity >

</ awarding >

</ manifest >

Step five: Working with the activity_main.xml file

Go to the activity_main.xml file and add together a text which will show "Welcome to GeeksforGeeks" when the user will enter into the MainActivity. Beneath is the lawmaking for the activity_main.xml file.

XML

<? xml version = "ane.0" encoding = "utf-8" ?>

< androidx.constraintlayout.widget.ConstraintLayout

android:layout_width = "match_parent"

android:layout_height = "match_parent"

android:groundwork = "#000"

tools:context = ".MainActivity" >

< TextView

android:layout_width = "wrap_content"

android:layout_height = "wrap_content"

android:text = "Welcome To GeeksforGeeks"

android:textColor = "@color/colorAccent"

android:textSize = "20dp"

app:layout_constraintBottom_toBottomOf = "parent"

app:layout_constraintLeft_toLeftOf = "parent"

app:layout_constraintRight_toRightOf = "parent"

app:layout_constraintTop_toTopOf = "parent" />

</ androidx.constraintlayout.widget.ConstraintLayout >

Step six: Working with the MainActivity.kt file

Do nothing in the MainActivity.kt file as nosotros already created a new activity for the Splash Screen. Below is the code for the MainActivity.kt file

Kotlin

import androidx.appcompat.app.AppCompatActivity

import android.os.Parcel

import android.widget.Toast

course MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

super .onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

}

}

Output

Notice this project on Github: https://github.com/Gauravverma245/AnimatedSplashScreen


Source: https://www.geeksforgeeks.org/how-to-create-an-animated-splash-screen-in-android/

Posted by: tracydeftern.blogspot.com

0 Response to "How To Give Launch Screen A Customed Class File For Animation"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel