본문 바로가기

Kotlin/안드로이드 공부

안드로이드12 Splash Screen

728x90

안드로이드 12 에서 기본 Splash Screen 관련 내용이 추가되었다.

SplashScreen API 를 사용하면 이전 버전에서도 적용할 수 있다. 단, 애니메이션과 브랜드 이미지는 불가능

implementation 'androidx.core:core-splashscreen:1.0.0'

 

cold start, warm start 일 때 발생하며, 앱이 첫 프레임을 그리는 즉시 닫힌다.

개발자가 정의한 테마와 애니메이션을 사용하여 스플래시 화면을 표시한다.

 

우리가 커스텀 할 수 있는 영역은,

1. 단색 배경색 설정

<item name="android:windowSplashScreenBackground">@color/...</item> // Android 12 이상
<item name="windowSplashScreenBackground">@color/...</item> // API 적용하여 사용할 떄

 

2. 아이콘 설정 

<item name="android:windowSplashScreenAnimatedIcon">@drawable/...</item>

벡터 드로어블이어야 한다.

기본적으로 앱 런처 아이콘이 표시된다.

안드로이드 12 에서는 AnimationDrawable, AnimatedVectorDrawable 애니메이션 벡터도 가능)

(안드로이드 13 에서는 지속시간 설정하지 않아도 알아서 유추함)

더보기

Splash Screen dimensions

The splash screen icon uses the same specifications as Adaptive icons, as follows:

  • Branded image: This should be 200×80 dp.
  • App icon with an icon background: This should be 240×240 dp, and fit within a circle of 160 dp in diameter.
  • App icon without an icon background: This should be 288×288 dp, and fit within a circle of 192 dp in diameter.

For example, if the full size of an image is 300×300 dp, the icon needs to fit within a circle with a diameter of 200 dp. Everything outside the circle will be invisible (masked).

 

3. 지속시간 설정

<item name="android:windowSplashScreenAnimationDuration">1000</item>

애니메이션 아이콘 설정시 지속 시간을 설정해주어야 한다.

스플래시 화면이 표시되는 실제 시간에는 영향을 미치지 않는다. 1000ms 이하 권장

 

 

 

4. 아이콘 뒤 배경색 설정

<item name="android:windowSplashScreenIconBackgroundColor">@color/...</item>

선택사항. 창 배경과 아이콘의 대비가 필요할 때 사용

 

 

5. 브랜딩 이미지 설정

<item name="android:windowSplashScreenBrandingImage">@drawable/...</item>

안드로이드 12 부터 가능하여 API 에서는 제공 안함

시작 화면 하단에 표시되며, 디자인 지침에서는 브랜딩 이미지를 권장하지 않음

너비 200dp, 높이 80dp 이내이며 이 비율을 맞추는 것이 좋음

 

 

6. 스플래시 화면에 아이콘을 표시할지 여부 설정

<item name="android:windowSplashScreenBehavior">icon_preferred</item>

안드로이드 13 이상에서만 가능

 

들어가기 애니메이션은 시스템에서 제어하고 맞춤 설정할 수 없다.

나가기 애니메이션은 스플래시 화면을 숨기는 애니메이션이며, 애니메이션이 완료될 때 스플래시 화면을 수동으로 삭제해주어야 한다.

 

 

7. splashscreen 처리가 끝나고 전환될 Theme

<item name="postSplashScreenTheme"></item>

API 에서 제공하는 속성으로, 기존에 쓰던 테마를 적어주면 된다.

 


매니페스트에서 위의 스타일 속성을 적용한 테마를 설정해주어야 하는데,

application 에 해야하는지 activity 에 해야하는지 헷갈려서 직접 다 해봤다.

공식 문서에서는 application or activity 라는 식으로 나와있음

app 에 스플래시 테마, activity 에 전체 테마 x
app 에 스플래시 테마, activity 에 테마 설정 안함 o
app 에 전체 테마, activity 에 스플래시 테마 o
app 에 스플래시 테마, activity 에 스플래시 테마 o

 

 

별도의 종료 애니메이션이 없는 경우라면 onCreate() 의 setContentView 이전에 installSplashScreen() 만 적어주면 된다.

override fun onCreate(savedInstanceState: Bundle?) {
    installSplashScreen()
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
}

 

종료 애니메이션

splashScreen.setOnExitAnimationListener { splashScreenView ->
    val scaleX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1f, 1.1f, 1.2f)
    val scaleY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f, 1.1f, 1.2f)

    ObjectAnimator.ofPropertyValuesHolder(splashScreenView.iconView, scaleX, scaleY).run {
        interpolator = AnticipateInterpolator()
        duration = 100L
        doOnEnd {
            splashScreenView.remove()
        }
        start()
    }
}

 

화면 유지

splashScreen.setKeepOnScreenCondition { true }

 

* 이것저것 테마 속성을 바꿔보면서 테스트해보는데 안드로이드 스튜디오 run 으로는 스플래시 화면이 뜨지 않는 문제가 있었다.

직접 다시 앱을 시키면 잘나온다...! 검색해보니 많이들 겪는 알려진 이슈인듯 ㅠㅠ

 

더보기

참고하면 좋을 사이트 https://itnext.io/a-comprehensive-guide-to-android-12s-splash-screen-api-644609c811fa

 

A Comprehensive Guide to Android 12’s Splash Screen API

For years Android Devs have always resorted to using a windowBackground or Activity or Fragment for their splash screen. Using the…

itnext.io

https://velog.io/@pachuho/Android-%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-12-Splash-Screen-%EC%A0%81%EC%9A%A9%ED%95%98%EA%B8%B0

 

[Android] 안드로이드 12 Splash Screen 적용하기

🛠 안드로이드 12 출시 한국시간으로 21년 10월 5일, 안드로이드 12가 출시되었습니다. 여러 변경점이 있었지만 그중에서도 앱을 시작하는 Spalsh Screen이 자동으로 생성되는 기능이 생겼습니다. 개

velog.io

https://www.kodeco.com/32555180-splash-screen-tutorial-for-android#toc-anchor-005

 

Splash Screen Tutorial for Android

Learn how to implement splash screen in new and existing Android apps, using the SplashScreen API introduced in Android 12.

www.kodeco.com

https://yggr.medium.com/exploring-android-12-splash-screen-21f88cc8e8f8

 

Exploring Android 12: Splash Screen

Android 12 introduces a new API for displaying Splash Screen. Let’s try out this feature together!

yggr.medium.com

https://medium.com/@radomir9720/android-splash-screen-easy-setup-for-both-11-version-and-lower-and-12-287ccb86f9c7

 

Android splash screen. Easy setup for both 11 version and lower, and 12.

Hi. In this article i will show you how to setup easily android splash screen. You don’t have to prepare images of different sizes…

medium.com

https://proandroiddev.com/splash-screen-in-android-3bd9552b92a5

 

Splash Screen in Android

An in-depth guide on the Android’s splash screen

proandroiddev.com