반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
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
Archives
Today
Total
관리 메뉴

코딩하기 좋은날

Deep Dive into Splash Screen - 1 본문

Android

Deep Dive into Splash Screen - 1

huiung 2022. 5. 8. 16:38
반응형

참조: Splash screens  |  Android Developers , Migrate your existing splash screen implementation to Android 12 and higher  |  Android Developers

SplashScreen

Android12이상을 사용하는 디바이스는 앱 실행시(Cold Start 또는 Warm Start 인 경우) 새로 추가된 SplashScreen이 반드시 나오도록 변경 되었다. 이를 따로 구현하지 않는다면, Android12 이상을 사용하는 디바이스에서는 default 화면(중앙에 앱 아이콘 및 App theme의 WindowBackground에 지정된 컬러를 배경색으로한)이 나타나게 된다. 이 화면은 앱의 첫 프레임이 그려질 때 사라지게 되므로, 대부분의 상황에서 아주 짧은순간 동안만 노출된다.

구글에서는 모든 앱의 스플래시 화면을 통일하고자 하는 의도가 있는 것으로 보인다. 따라서 기존에 앱에서 자체적으로 가지고 있던 Splash 화면은 제거할 것을 구글은 추천하고 있다. 자체적인 Splash 화면을 띄운다면 2개의 Splash화면이 뜨게 될 것이다.

SplashScreen을 커스터마이징 할 수 있는 영역은 아래와 같이 4가지 영역이다.

style의 attribute 값을 조정하여 해당 값들을 커스터마이징 할 수 있으며 추가적으로 화면이 사라질 때 ExitAnimationListener를 커스텀하거나, 데이터 로드등을 이유로 SplashScreen이 사라지는 시점을 조절 할 수 있다. 자세한 구현 방법은 문서 상단의 공식문서 링크를 참조하고, 여기서는 해당 내용에 대해서는 자세히 다루지 않을 것이다.

Migrate your splash screen implementation

안드로이드 11이하 버전에서도 동일한 스플래시 화면을 제공하기 위해 splash screen compat library가 제공된다.

완벽한 호환은 되지 않는다. 다음은 호환이 되지 않는 사항들이다.

  • API 31 미만에서는 AnimatedIcon이 Animated 되지 않는다.
  • API 21-22 에서는 application이 시작할 때 까지 icon이 보이지 않을 것이다. (API LEVEL 23부터 추가된 adjustInset()을 사용하지 못하기 때문이다.)
  1. dependency 추가
1dependencies {
2   ...
3   implementation 'androidx.core:core-splashscreen:1.0.0-beta02'}
4}
  1. Theme.SplashScreen을 parent로 가지는 Theme를 만든다. 그리고 SplashScreen이 끝나고 나서 Activity가 사용해야 하는 Theme 값을 postSplashScreenTheme 에 추가해주어야 한다.
1<style name="Theme.App.Starting" parent="Theme.SplashScreen">
2// Set the splash screen background, animated icon, and animation duration.
3   <item name="windowSplashScreenBackground">@color/...</item>
4
5// Use windowSplashScreenAnimatedIcon to add either a drawable or an
6// animated drawable. One of these is required.
7   <item name="windowSplashScreenAnimatedIcon">@drawable/...</item>
8   <item name="windowSplashScreenAnimationDuration">200</item>  # Required for
9                                                                # animated icons
10
11// Set the theme of the Activity that directly follows your splash screen.
12   <item name="postSplashScreenTheme">@style/Theme.App</item>  # Required.
13</style>
  1. Manifest에서 starting activity의 theme를 변경한다.
1<manifest>
2   <application android:theme="@style/Theme.App.Starting">
3    <!-- or -->
4        <activity android:theme="@style/Theme.App.Starting">
5...
  1. starting activity에서 super.onCreate()가 호출되기 전에 installSplashScreen()을 호출해라.
1class MainActivity : Activity() {
2
3   override fun onCreate(savedInstanceState: Bundle?) {
4// Handle the splash screen transition.
5       val splashScreen = installSplashScreen()
6
7       super.onCreate(savedInstanceState)
8       setContentView(R.layout.main_activity)
9...

installSplashScreen()은 splashScreen 객체를 리턴한다. 이 객체를 통해 splashScreen의 커스터마이징이 가능하다.

 

2편에서는 해당 화면이 어디서 그려지고 어떻게 붙고, 제거되는지 확인해본다.

https://huiung.tistory.com/193

반응형