๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Study/Android

[์•ˆ๋“œ๋กœ์ด๋“œ ์ฝ”ํ‹€๋ฆฐ] ํ”„๋กœ์ ํŠธ - ์Šคํ”Œ๋ž˜์‰ฌ

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>

 

 

๊ฒฐ๊ณผ