| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 
| 12 | 13 | 14 | 15 | 16 | 17 | 18 | 
| 19 | 20 | 21 | 22 | 23 | 24 | 25 | 
| 26 | 27 | 28 | 29 | 30 | 31 | 
													Tags
													
											
												
												- android recyclerview
- 습관만들기
- Android ViewPager2
- 영어공부
- 안드로이드 카카오 로그인
- scope function
- Android 12 대응
- 66챌린지
- Android 12
- 알고리즘 자바
- Android WebView
- DataBinding
- 안드로이드
- WebView
- Android Navigation
- Android Interceptor
- Kotlin
- Kotlin FCM
- Android
- 영어독립365
- 안드로이드 갤러리 접근
- MVP Architecture
- OkHttp Interceptor
- Java
- 프로그래머스 알고리즘
- coroutine
- 코틀린 코루틴
- Android ProgressBar
- Android Jetpack
- 카카오 알고리즘
													Archives
													
											
												
												- Today
- Total
나미래 Android 개발자
Android Splash Screen 예제(Kotlin) 본문
Android Splash Screen 예제(Kotlin)
개요
스플래시 화면을 통해 앱의 고유한 브랜딩을 유지할 수 있다.
실행화면

프로젝트 구조(이미지)

Splash Screen Activity 만들기
SplashScreen.kt
일정 시간 이후, MainActivity 로 이동한다.
class SplashScreen : AppCompatActivity() {
    private val splashDuration = 1500L
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash_screen)
        // Handler()를 통해서 UI 쓰레드를 컨트롤 한다.
        // Handler().postDelayed(딜레이 시간){딜레이 이후 동작}
        //      postDelayed()를 통해 일정 시간(딜레이 시간)동안 쓰레드 작업을 멈춘다.
        //      {딜레이 이후 동작}을 통해 딜레이 시간 이후, 동작을 정의해준다.
        Handler().postDelayed(splashDuration){
            val intent = Intent(this, MainActivity::class.java)
            startActivity(intent)
            finish()
        }
    }
}activity_splash_screen.xml
스플래쉬 화면을 만든다.
<?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="#FF5722"
    tools:context=".SplashScreen">
    <ImageView
        android:layout_width="250dp"
        android:layout_height="300dp"
        android:src="@drawable/ic_android"
        app:layout_constraintBottom_toBottomOf="@id/tvSplashScreen"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <TextView
        android:id="@+id/tvSplashScreen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Splash Screen"
        android:textColor="@color/white"
        android:textSize="40sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>앱 시작 Activity 변경하기
AndroidManifest.xml
새로 만든 SplahScreen Activity 태그 안에 <intent-filter> 태그를 넣어준다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.splashapplication">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.SplashApplication">
        <activity
            android:name=".SplashScreen"
            android:exported="true" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:exported="true">
        </activity>
    </application>
</manifest>스플래쉬 이후 Activity
MainActivity.kt
스플래쉬 화면 사용 방법만을 설명하려 했기 때문에, 이후 화면에는 EmptyActivity 기본 값으로 되어 있다.
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}'안드로이드' 카테고리의 다른 글
| Android Naver Map - MapView 기본 사용 예제 (Kotlin) (0) | 2021.12.07 | 
|---|---|
| Android RecyclerView with DataBinding Example (0) | 2021.12.03 | 
| 갤러리 접근: 프로필 이미지 변경 (0) | 2021.11.23 | 
| Android DB - SharedPreferences 예제(Kotlin) (0) | 2021.11.10 | 
| 안드로이드 원형 버튼 만들기 (4) | 2021.11.08 | 
			  Comments
			
		
	
               
           
					
					
					
					
					
					
				