Android Create Splash Screen In Kotlin

June 05, 2018 , 0 Comments

Here in this tutorial i am going to explain you about creating a splash screen in Kotlin language. A splash screen is the first launching activity of the applications which waits for certain seconds and go to the next page either to login page or home page of the application. Splash screen is common to most of the mobile applications . It is very simple to create a splash screen using a Handler class.


If you are using Android Studio 3.0 or above then please start creating the project as Kotlin Project. If you are using an older version of Android Studio IDE then please add Kotlin plugin from JetBrains and configure Kotlin into the project.


Step 1: Create A Layout XML file


Create a layout res/layout/activity_splash.xml



xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context="devdeeds.com.kotlinsplashscreen.SplashActivity">


android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:text="@string/loader_text"
android:textColor="#000"
android:textSize="25sp" />



Step 2: Create SplashActivity Class


SplashActivity.kt



import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.support.v7.app.AppCompatActivity

/**
* A sample splash screen created by devdeeds.com
* by Jayakrishnan P.M
*/
class SplashActivity : AppCompatActivity() {
private var mDelayHandler: Handler? = null
private val SPLASH_DELAY: Long = 3000 //3 seconds

internal val mRunnable: Runnable = Runnable {
if (!isFinishing) {

val intent = Intent(applicationContext, HomeActivity::class.java)
startActivity(intent)
finish()
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)

//Initialize the Handler
mDelayHandler = Handler()

//Navigate with delay
mDelayHandler!!.postDelayed(mRunnable, SPLASH_DELAY)

}

public override fun onDestroy() {

if (mDelayHandler != null) {
mDelayHandler!!.removeCallbacks(mRunnable)
}

super.onDestroy()
}

}

Add Splash Activity As The Launch Page In Manifest


res/layout/activity_splash.xml




package="devdeeds.com.kotlinsplashscreen">

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">
android:name=".SplashActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@style/FullscreenTheme">











Result




GitHub-Mark-32pxDownload Source Code


The post Android Create Splash Screen In Kotlin appeared first on DevDeeds.

siddharth makadiya

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments:

Popular Posts