스플래시 화면 추가

앱이 맞춤 스플래시 화면을 구현하거나 런처 테마를 사용하는 경우 Jetpack에서 제공되는 SplashScreen 라이브러리로 앱을 이전하여 모든 Wear OS 버전에서 올바르게 표시되도록 합니다.

화면이 디자인 가이드라인을 준수하도록 SplashScreen 라이브러리를 사용하여 스플래시 화면을 추가하는 방법을 알아보려면 이 페이지의 단계별 구현 안내를 참고하세요.

종속 항목 추가

앱 모듈의 build.gradle 파일에 다음 종속 항목을 추가합니다.

Groovy

dependencies {
    implementation "androidx.core:core-splashscreen:1.2.0-alpha01"
}

Kotlin

dependencies {
    implementation("androidx.core:core-splashscreen:1.2.0-alpha01")
}

기본 Wear OS 크기 지원을 받으려면 버전 1.0.1 이상을 사용해야 합니다.

테마 추가

res/values/styles.xml에서 스플래시 화면 테마를 만듭니다. 상위 요소는 아이콘의 모양에 따라 다릅니다.

  • 아이콘이 둥근 경우 Theme.SplashScreen을 사용합니다.
  • 아이콘이 다른 모양이면 Theme.SplashScreen.IconBackground를 사용합니다.

windowSplashScreenBackground를 사용하여 배경을 검은색 단색으로 채웁니다. postSplashScreenTheme의 값을 Activity에서 사용해야 하는 테마로 설정하고 windowSplashScreenAnimatedIcon을 드로어블 또는 애니메이션된 드로어블로 설정합니다.

<resources>
    <style name="Theme.App" parent="@android:style/Theme.DeviceDefault" />

    <style name="Theme.App.Starting" parent="Theme.SplashScreen">
        <!-- Set the splash screen background to black -->
        <item name="windowSplashScreenBackground">@android:color/black</item>
        <!-- Use windowSplashScreenAnimatedIcon to add a drawable or an animated
             drawable. -->
        <item name="windowSplashScreenAnimatedIcon">@drawable/splash_screen</item>
        <!-- Set the theme of the Activity that follows your splash screen. -->
        <item name="postSplashScreenTheme">@style/Theme.App</item>
    </style>
</resources>

아이콘이 원형이 아닌 경우 바탕에 흰색 배경색을 설정해야 합니다. 이 경우 Theme.SplashScreen.IconBackground를 상위 테마로 사용하고 windowSplashScreenIconBackgroundColor 속성을 설정합니다.

<style name="Theme.App.Starting" parent="Theme.SplashScreen.IconBackground">
    ...
    <!-- Set a white background behind the splash screen icon. -->
    <item name="windowSplashScreenIconBackgroundColor">@android:color/white</item>
</style>

다른 속성은 선택사항입니다.

테마의 드로어블 만들기

스플래시 화면 테마를 사용하려면 windowSplashScreenAnimatedIcon 속성에 드로어블을 전달해야 합니다. 예를 들어 새 파일 res/drawable/splash_screen.xml을 추가하고 앱 런처 아이콘과 올바른 스플래시 화면 아이콘 크기를 사용하여 만들 수 있습니다.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:width="@dimen/splash_screen_icon_size"
        android:height="@dimen/splash_screen_icon_size"
        android:drawable="@mipmap/ic_launcher"
        android:gravity="center" />
</layer-list>

스플래시 화면 아이콘 크기는 res/values/dimens.xml에서 정의되며 아이콘이 원형인지에 따라 다릅니다.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Round app icon can take all of default space -->
    <dimen name="splash_screen_icon_size">48dp</dimen>
</resources>

...또는 원형이 아니면 아이콘 배경을 사용해야 합니다.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- Non-round icon with background must use reduced size to fit circle -->
    <dimen name="splash_screen_icon_size">36dp</dimen>
</resources>

테마 지정

앱의 매니페스트 파일(AndroidManifest.xml)에서 시작 활동의 테마(일반적으로 런처 항목을 정의하는 테마 또는 다른 방식으로 내보내진 테마)를 이전 단계에서 만든 테마로 바꿉니다.

<manifest>
    <application android:theme="@style/Theme.App.Starting">
       <!-- or -->
       <activity android:theme="@style/Theme.App.Starting">
          <!-- ... -->
</manifest>

시작 활동 업데이트

super.onCreate()를 호출하기 전에 시작 활동에 스플래시 화면을 설치합니다.

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        // Handle the splash screen transition.
        installSplashScreen()

        super.onCreate(savedInstanceState)
        setContent {
            WearApp("Wear OS app")
        }
    }
}

추가 리소스

일반적인 스플래시 화면과 앱에서 이를 사용하는 방법을 자세히 알아보세요.