2023.7.25
1. μ€λΉ
- μ΄λ―Έμ§ μ€λΉ
- SplashActivity.kt
- activity_splash.xml
2. activity_splash.xml μμ±
- background μ΄λ―Έμ§λ‘ μ 체 μ΄λ―Έμ§λ₯Ό μ£Όμλ€.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="@drawable/splash_screen"
tools:context=".SplashActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
2. themes.xml μμ±
- res > values > themes
- windowNoTitle: μλ¨ νμ΄ν λ°
- windowFullscreen: νμ€ν¬λ¦° λͺ¨λ (μλ¨ μ‘μ λ°μ μνλ° λͺ¨λ νμX)
<style name="Theme.Splash" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
3. SplashActivity.kt μμ±
- Handler ν¨μ μ΄μ©
package com.example.bartest
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
Handler().postDelayed({
// You can declare your desire activity here to open after finishing splash screen. Like MainActivity
val intent = Intent(this,MainActivity::class.java)
startActivity(intent)
finish()
}, 3000) // 3μ΄λ€ λ€μ νλ©΄(MainActivity)λ‘ μ΄λ
}
}
4. AndroidManifest.xml
- android:name=".MainActivity"μ android:name=".SplashActivity" μμ (λμ λ°κΏμ€)
- <intent-fliter> μλ λΆλΆμ΄ μ²μ μ€νμμΌ°μ λ λμ€λ νλ©΄
- android:theme="@style/Theme.Splash" μΆκ°
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.BarTest"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="false" />
<activity
android:name=".SplashActivity"
android:exported="true"
android:theme="@style/Theme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
κ²°κ³Ό