원본출처: 티스토리 바로가기
https://medium.com/@umairkhalid786/splash-screen-api-android-701cfaaf7b70
오늘은 medium 에서 만난 글 하나를 소개 하고자 한다. splash screen api 에 대한 부분이다. 예전에는 splash 화면을 만들기 위해서 acitivy 하나를 추가해서 만들고 해당 activity 을 실행하게 해서 구현했던 기억이 있다.
https://billcorea.tistory.com/45
이때는 이렇게 만들었는 데 말이다. android 가 12로 올라가면서 api 가 추가 되었다. 저 위에 글쓴이의 말은 이해가 될 것 같기도 하다가. 그렇지 않기도 해서 여기 저기 찾다가 구현을 해 보았다.
먼저. gradle 에 추가할 부분은 다음과 같이
dependencies { .... implementation 'androidx.core:core-splashscreen:1.0.0-beta01' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1' ..... }
viewmodel 은 왜 들어가야 하는 가 ? 그것 아직 잘 이해가 되지는 않았다. 뭐 그래도 필요한 듯 하여...
다음은 splah 화면으로 사용할 theme 을 추가 한다. res / values 폴더에 splash_theme.xml 로
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="Theme.App.Starting" parent="Theme.SplashScreen"> <!-- I will rather have a splash screen with animated drawable icon <item name="windowSplashScreenBackground">@color/purple_200</item> --> <item name="windowSplashScreenAnimatedIcon">@drawable/dice_1</item> <item name="windowSplashScreenAnimationDuration">100</item> <item name="postSplashScreenTheme">@style/Theme.KotlinExam0115</item> </style> </resources>
여기서 볼껀
windowSplashScreenBackground 을 사용하면 배경색 지정이 된다는 것이다.
windowSplashScreenAnimatedIcon 을 이미지 아이콘을 지정하는 것이다. 저기서 지정한 dice_1 은 샘플 코딩 하다가 만든 png 파일이다.
windowSplashScreenAnimationDuration 은 지속시간을 말하는 것이고
postSplashScreenTheme 는 내 앱 theme 을 지정해 주었다. (ex : Theme.KotlinExample0115 는 내가 만든 앱의 기본 style theme 명칭임)
다음은 acitivy 의 구현 부분 인데...
import android.animation.ObjectAnimator import android.os.Bundle import android.util.Log import android.view.View import android.view.animation.AnticipateInterpolator import androidx.appcompat.app.AppCompatActivity import androidx.core.animation.doOnEnd import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import kotlin.concurrent.thread class MainActivity : AppCompatActivity() { var TAG:String = "MainActivity" override fun onCreate(savedInstanceState: Bundle?) { val splashScreen = installSplashScreen() super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) splashScreen.apply { setOnExitAnimationListener { sp -> sp.iconView.animate().rotation(180F).duration = 3000L val slideUp = ObjectAnimator.ofFloat( sp.iconView, View.TRANSLATION_Y, 0f, -sp.iconView.height.toFloat() ) slideUp.interpolator = AnticipateInterpolator() slideUp.doOnEnd { sp.remove() } slideUp.start() } } } }
이 정도의 구현... 먼저 splashScreen 을 선언해 주고. 아래 에서 일정시간 동안 동작하고 꺼지는 화면을 구현 하도록 만들어 주는 정도가 되면 될 것 같다. 안드로이드 개발자 가이드는 아래 링크를 참고 하였다.
https://developer.android.com/guide/topics/ui/splash-screen
실행되는 영상 이미지는 이렇게 동작을 한다. 저 주사위 이미지가 나왔다가. 사라지는 모양으로... 응용해 보면 되지 않을 가 ?
이것으로 오늘은 정리 끝.
댓글
댓글 쓰기