반응형
1. splash screen api 추가
build.gradle 에 splashscreen api 를 추가하려면
1.0.1 버전 적용하세요
아직 1.1.0-alpha 버전 사용하지 마세요. = > Android 14 설정 하니 구글 플레이스토어까지 문제 없는데
사용자들이 다운 및 설치가 안됩니다.
Android 14 적용해야 합니다.
defaultConfig {
...
//splash screen
implementation 'androidx.core:core-splashscreen:1.0.1'
2. logo xml 준비
도스게임 플레이어 로고를 xml 로 준비해서
res > drawalbe 에 logo_svg.xml 로 추가
3. splash 용 theme 추가
icon, 배경색, splash 이후 테마 설정
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">@drawable/logo_svg</item>
<item name="windowSplashScreenBackground">#000000</item>
<item name="postSplashScreenTheme">@style/Theme.Main</item>
</style>
4. manifest 에 처음 테마를 설정
splash Activity 삭제
application 과 mainActivity 의 테마를 Theme.App.Starting 으로 변경
<application
android:name=".MainApplication"
android:theme="@style/Theme.App.Starting"
...
<activity
android:name=".ui.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
android:exported="true"
android:theme="@style/Theme.App.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
5. ViewModel 에 Splash 상태 관리 추가
기존에 사용하던 MainViewModel 에 상태 하나 추가
...
private val _postSplashTheme = MutableStateFlow(true)
val postSplashTheme = _postSplashTheme.asStateFlow()
...
init {
...
viewModelScope.launch {
delay(2000)
_postSplashTheme.value = false
}
}
6. MainActivity 에 SplashScreen API 추가
onCreate 안에 installSplashScreen() 을 추가하고
setContent 앞에서 splashScreen.setKeepOnScreenCondition 을 설정하면
mainViewModel 에서 처리할 꺼 다 처리한다음에 false 던져주면
setContent 가 실행되는 형식 입니다.
//by viewModels 를 사용하면 Activity 라이프사이클로 종속됨
private val mainViewModel : MainViewModel by viewModels()
private val aboutViewModel : AboutViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)
...
splashScreen.setKeepOnScreenCondition {
mainViewModel.postSplashTheme.value
}
setContent {
...
적용은 다 되었는데
vector 로고가 그지 같아서 로고 파일을 다시 손봐야 하네요.
반응형
'IT > 안드로이드' 카테고리의 다른 글
png to xml for android logo (0) | 2023.07.13 |
---|---|
jetpack compose Review URL Open (0) | 2023.07.13 |
Android Coroutine 의 Dispatcher 종류와 사용방법 (0) | 2023.06.27 |
안드로이드 기기 카탈로그 (android catalog) (1) | 2023.05.08 |
jetpack compose paging3 사용시 주의사항 (immutable 데이터만 사용) (1) | 2023.05.08 |
android studio different debug vs release libraries version (0) | 2023.04.26 |
안드로이드 코드명과 빌드 번호 참고 (0) | 2023.03.11 |
jetpack compose 에서 MutableStateFlow vs MutableState (0) | 2023.02.16 |