Langkah 1: Create A Layout XML file
Create a layout
res/layout/activity_splash.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 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"> <!-- The primary full-screen view. This can be replaced with whatever view is needed to present your content, e.g. VideoView, SurfaceView, TextureView, etc. --> <TextView 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" /> </FrameLayout>
Langkah 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
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="devdeeds.com.kotlinsplashscreen"> <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=".SplashActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name" android:theme="@style/FullscreenTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".HomeActivity" /> </application> </manifest>
Hasil
Share : Splash Screen dengan Kotlin
Splash Screen dengan Kotlin
4/
5
Oleh
anovandi
0 comments : Splash Screen dengan Kotlin
0 comments : Splash Screen dengan Kotlin