Make a Splash Screen in Android Studio and Kotlin



in this tutorial, I will show you how to make a Splash screen using Kotlin and Android Studio.
Having a Splash screen is very important if you want that your app looks professional and to promote your brand, it's also a good way to make your user wait while you have some data that are loading in a background process.

I-Create a new project

First, you have to create a new project, you can call it whatever you want, and we will need to create a new activity that we will call " SplashActivity " and we will need to make it a launcher activity like in the image below.






now we need to create the design of our splash screen, we will make a simple layout that contains an image that will represent your app logo, so don't forget to use a custom logo and change it in the image resource

splash_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:gravity="center"
    tools:context=".SplashActivity">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"
        android:textSize="30sp"
        android:textAlignment="center"
        android:layout_marginVertical="10dp"
        />
    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
</LinearLayout>


now we will need to create a handler inside the SplashActivity.kt file. I am not going to explain the handler object because it needs a whole course for it, but I will send you to a link that will explain you in details: How Looper, MessageQueue, Handler work in Android
For the moment, the Handler Object will allow us to load the splash activity for a while and then it will send us to our main activity. For this, we will use the postDealyed method.

SplashActivity.kt:

class SplashActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        //Now we need to create a Handler to make the splash screen  wait for 3 second before
        // it launch the main activity

        val handler = Handler()
        handler.postDelayed({
            //Here we can create an intent to open the main activity
            val intent = Intent(this,MainActivity::class.java)
            startActivity(intent)
        },3000)// the splash screen will be visible for 3000 millisecond
    }
}


and that's it, you can customize your splash screen as you like and make the design that you want.
of course, we will see in the future course how can we load the splash screen until we load all user data or news feed.
I hope that you liked this tutorial, please tell us in the comment if you want new courses and what kind of project you want to build
Make a Splash Screen in Android Studio and Kotlin Make a Splash Screen in Android Studio and Kotlin Reviewed by Medics on March 13, 2020 Rating: 5

No comments:

-->
Powered by Blogger.