안드로이드 앱 만들때 진입화면
스플래쉬(Splash) 화면을 만들어서 로고도 보여주고
메인 화면으로 넘어간다
만드는 방법
- 강제로 3초 딜레이 주는 방법
 
- 이미지 이용해서 구현하는 방법
 
뭘 선택하느냐는 취향차이
강제로 3초 딜레이 주는 방법
스플래쉬 화면 하나 만들고
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
   | <?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="#11111f"     tools:context=".activity.SplashActivity">
      <ImageView         android:id="@+id/imageview_splash_logo"         android:layout_width="150dp"         android:layout_height="150dp"         android:layout_marginTop="150dp"         android:contentDescription="@string/all_logo"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent"         app:srcCompat="@drawable/all_logo" />
      <ImageView         android:id="@+id/imageview_splash_appname"         android:layout_width="268dp"         android:layout_height="189dp"         android:layout_marginTop="150dp"         android:contentDescription="@string/all_appname"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toBottomOf="@id/imageview_splash_logo"         app:srcCompat="@drawable/all_appname" /> </androidx.constraintlayout.widget.ConstraintLayout>
   | 
 
화면 컨트롤하는 액티비티 만들고
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 32 33 34
   | package com.skyksit.dsam3.activity
  import android.annotation.SuppressLint import android.content.Intent import android.os.Build import android.os.Bundle import android.os.Handler import android.os.Looper import android.view.WindowInsets import android.view.WindowManager import androidx.appcompat.app.AppCompatActivity import com.skyksit.dsam3.R
  @SuppressLint("CustomSplashScreen") class SplashActivity  : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContentView(R.layout.activity_splash)
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {             window.insetsController?.hide(WindowInsets.Type.statusBars())         } else {             window.setFlags(                 WindowManager.LayoutParams.FLAG_FULLSCREEN,                 WindowManager.LayoutParams.FLAG_FULLSCREEN             )         }         Handler(Looper.getMainLooper()).postDelayed({             val intent = Intent(this, GameListActivity::class.java)             startActivity(intent)             finish()         }, 3000)     } }
   | 
 
Splash 가 사용하는 테마 만들고
1 2 3 4 5 6 7
   | <style name="Theme.SplashScreen" parent="Theme.AppCompat.Light.NoActionBar">     <item name="android:windowContentOverlay">@null</item>     <item name="android:windowIsTranslucent">true</item>     <item name="android:windowDisablePreview">true</item>     <item name="windowActionBar">false</item>     <item name="windowNoTitle">true</item> </style>
   | 
 
안드로이드 manifest 파일에서 SplashScreen 이 진입으로 설정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
   | <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" 	package="com.example.splashscreeninandroid">
  	<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/AppTheme"> 		<activity android:name=".MainActivity"></activity> 		<activity 			android:name=".SplashScreen" 			android:theme="@style/Theme.SplashScreen"> 			<intent-filter> 				<action android:name="android.intent.action.MAIN" /> 				<category android:name="android.intent.category.LAUNCHER" /> 			</intent-filter> 		</activity> 	</application>
  </manifest>
   | 
 
이미지 이용해서 구현하는 방법
테마를 만들고
1 2 3 4
   |      <style name="Theme.Splash" parent="Theme.MaterialComponents.DayNight.NoActionBar">         <item name="android:windowBackground">@drawable/splash_background</item>     </style>
 
  | 
 
drawable 에 splash_background 만들고
여기서 조정한다
background 색상, 로고, 설명 필요없는 건 빼면된다
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
   | <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">     <item         android:drawable="@drawable/splash_bg_gradient"/>     <item>         <bitmap             android:gravity="center"             android:src="@drawable/splash_logo_1"/>     </item>     <item android:bottom="50dp">         <bitmap             android:gravity="center"             android:src="@drawable/splash_logo_2"/>     </item> </layer-list>
   | 
 
위에 표시한 drawable 을 추가해준다
AndroidManifest 수정
1 2 3 4 5 6 7 8 9
   | <activity     android:name=".SplashScreenActivity"     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>
   | 
 
SplashScreenActivity 생성
1 2 3 4 5 6 7 8 9 10 11 12 13
   | package com.skyksit.dsam3
  import android.content.Intent import android.os.Bundle import androidx.appcompat.app.AppCompatActivity
  class SplashScreenActivity  : AppCompatActivity() {     override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         val nextIntent = Intent(this, GameListActivity::class.java)         startActivity(nextIntent)     } }
   | 
 
장점은 3초 딜레이를 강제로 주지 않기 때문에
콜드 스타트 시간을 당길 수 있다
next 화면이 준비 되면 바로 넘어간다