λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

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>

 

 

κ²°κ³Ό