Development record of developer who study hard everyday.

, , ,

안드로이드 12 SplashScreen 없애는 방법

 안드로이드 12 SplashScreen 없애는 방법

안드로이드 개발 블로그

구글이 희대의 뻘짓을 한 것 같다...

안드로이드 12부터 SplashScreen 이란 개념을 도입했다.

우리가 그 동안 흔히 써왔던 SplashActivity를 구글 자체 라이브러리로 도입하는 것이다.

하지만 제약도 너무 많고(구글은 통일성이라고 우기겠지??) 이걸 누가 얼마나 쓸지 모르겠다.

에이전시 회사인 우리 회사도 그냥 SplashScreen을 안보이게하고 기존의 방식대로 SplashActivity를 사용하고 있다.

괜히, 해야하는 일이 늘어난 것이다.ㅜㅜ

그렇다면 울며 겨자먹기로 SplashScreen을 안보이게 하는 방법을 알아보자.


1. dependency 추가하기

dependencies {

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

}

build.gradle 앱수준 파일에 splashscreen을 추가해준다.

참고로 이 라이브러리를 추가하기위해서는 targetSdkVersion과 compileSdkVersion이 31이상이여야한다.


2. drawable 만들기

 res - drawable 디렉토리 아래에 white.xml 파일을 만들어준다.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white"/>
</shape>

white.xml 파일은 splashScreen에서 앱 아이콘 대신 쓰일 거다.


3. Theme 만들기

스플래시 스크린에 사용할 Theme을 만들어야한다.

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="@style/BaseTheme">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>


<style name="SplashTheme" parent="AppTheme">
<item name="android:windowSplashScreenBackground" tools:targetApi="S">@color/white</item> //스플래시 화면 바탕색
<item name="android:windowSplashScreenAnimatedIcon" tools:targetApi="S">@drawable/white</item> //스플래시 화면 정중앙 아이콘
<item name="postSplashScreenTheme">@style/AppTheme</item> //스플래시 이후 띄울 화면의 테마
</style>

</resources>

위 코드처럼 SplashTheme 테마를 만들어준다.


4. manifest.xml 파일에서 테마 적용하기

<activity android:name="com.appg.youth.market.main.MainActivity"
android:theme="@style/SplashTheme"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

manifext.xml 파일에 들어가서 맨 처음 시작하는 activity에 android:theme="@style/SplashTheme" 을 적용해준다.


5. installSplashScreen() 호출

맨 처음 시작하는 액티비티의 클래스에 가서 onCreate() 부분에 installSplashScreen()을 호출해준다.

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()    //반드시 super.onCreate 위에서 호출!!
super.onCreate(savedInstanceState)
binding.viewModel = viewModel

init()
}

반드시 super.onCreate(savedInstanceState) 보다 위에서 호출해야한다!!

이런식으로해서 안드로이드 12의 기본 스플래시 스크린을 안보이게하고 기존의 스플래시 화면을 계속 사용할 수 있다.

다시 한 번 강조하지만, 구글이 엄한 짓을 했다.



Share:

댓글 없음:

댓글 쓰기