How To Create Splash Screen Animation In Nativescript
Prerequisites: How to Create a Splash Screen in Android using Kotlin?
Android Splash Screen is the kickoff screen visible to the user when the application's launched. Splash Screen is the user's first experience with the application that's why it is considered to be one of the well-nigh vital screens in the application. Information technology is used to brandish some data about the company logo, company proper noun, etc. We can as well add some animations to the Splash screen too. In this commodity, we volition be making an animated Splash Screen Using Kotlin.A sample GIF is given below to get an idea about what we are going to do in this article.
Steps to Create an Animated Splash Screen
Stride i: 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.
Step 2: Create an blitheness file
To create an animation file in android studio please follow the given instructions carefully. Get to the app > res > correct-click > New > Android Resource Directory.
Then name the directory name as anim. And then click on OK.
Get to the anim > right-click > New > Animation Resources File
And proper noun the file proper name as side_slide and click on OK.
Now add this code to the blithe XML file. Below is the code for the side_slide.xml file.
XML
<?
xml
version
=
"i.0"
encoding
=
"utf-8"
?>
<
ready
<
interpret
android:duration
=
"1500"
android:fromXDelta
=
"-50%"
android:fromYDelta
=
"0%"
/>
<
blastoff
android:elapsing
=
"1500"
android:fromAlpha
=
"0.1"
android:toAlpha
=
"1.0"
/>
</
set
>
Step 3: Create another activeness
Go to app > java > first parcel proper noun > right-click > New > Activity > Empty Activity and create another activeness and named it every bit SplashScreen. Edit the activity_splash_screen.xml file and add together image, text in the splash screen as per the requirement. Here we are adding an image to the splash screen. Beneath is the code for the activity_splash_screen.xml file.
XML
<?
xml
version
=
"1.0"
encoding
=
"utf-eight"
?>
<
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 code. Below is the lawmaking for the SplashScreen.kt file. Comments are added inside the code to sympathise the code in more particular.
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"
)
class
SplashScreen : AppCompatActivity() {
override fun onCreate(savedInstanceState: Package?) {
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::
grade
.java)
startActivity(intent)
stop()
},
3000
)
}
}
Step four: 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 hibernate the status bar or action bar.
android:theme="@manner/Theme.AppCompat.Light.NoActionBar"
Also, add <intent-filter> within the Splash Screen Activity to make this activity as the starting action. So whenever the app will execute the user can meet the splash screen at the beginning. Below is the consummate code for the AndroidManifest.xml file.
XML
<?
xml
version
=
"one.0"
encoding
=
"utf-eight"
?>
bundle
=
"com.case.animatedsplashscreen"
>
<
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/AppTheme"
>
<
activity
android:name
=
".MainActivity"
></
activity
>
<
activeness
android:proper name
=
".SplashScreen"
android:theme
=
"@fashion/Theme.AppCompat.Light.NoActionBar"
>
<
intent-filter
>
<
action
android:name
=
"android.intent.activeness.Master"
/>
<
category
android:name
=
"android.intent.category.LAUNCHER"
/>
</
intent-filter
>
</
activity
>
</
application
>
</
manifest
>
Step 5: Working with the activity_main.xml file
Go to the activity_main.xml file and add a text which will show "Welcome to GeeksforGeeks" when the user will enter into the MainActivity. Below is the code for the activity_main.xml file.
XML
<?
xml
version
=
"1.0"
encoding
=
"utf-eight"
?>
<
androidx.constraintlayout.widget.ConstraintLayout
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
android:background
=
"#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 6: Working with the MainActivity.kt file
Do null in the MainActivity.kt file as we already created a new activity for the Splash Screen. Below is the lawmaking for the MainActivity.kt file
Kotlin
import
androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.widget.Toast
class
MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Packet?) {
super
.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Output
Find this projection on Github: https://github.com/Gauravverma245/AnimatedSplashScreen
Source: https://www.geeksforgeeks.org/how-to-create-an-animated-splash-screen-in-android/
Posted by: robersonbles1976.blogspot.com
0 Response to "How To Create Splash Screen Animation In Nativescript"
Post a Comment