티스토리 뷰

반응형

스플래시 화면으로 쓸 액티비티를 하나 생성하고(empty activity) 로딩 타임 설정을 해준다

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler

class splash_activity : AppCompatActivity() {

    // This is the loading time of the splash screen
    private val SPLASH_TIME_OUT:Long = 3000 // 1 sec
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash_activity)


        Handler().postDelayed({
            // This method will be executed once the timer is over
            // Start your app main activity

            startActivity(Intent(this, LoginActivity::class.java))

            // close this activity
            finish()
        }, SPLASH_TIME_OUT)
    }
}

 

그다음에 xml파일에는 원하는 UI를 적용하고

 

manifest에 이 코드만 추가해주면 끝

<activity android:name=".splash_activity"
    android:theme="@style/AppTheme.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

 

간단하다

 

 

 

참고한 포스팅

 

https://levelup.gitconnected.com/a-tutorial-on-building-a-splash-screen-with-kotlin-in-android-studio-dc647cd52f9b

 

A Tutorial on Building a Splash Screen with Kotlin in Android Studio

Build a splash screen for your Android app from scratch

levelup.gitconnected.com

 

반응형