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>
๊ฒฐ๊ณผ