0% found this document useful (0 votes)
6 views7 pages

SplashScreen - Android Developers

Uploaded by

Hien Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

SplashScreen - Android Developers

Uploaded by

Hien Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

8/9/24, 10:30 AM SplashScreen | Android Developers

SplashScreen
Artifact: androidx.core:core-splashscreen (/jetpack/androidx/releases/core)
View Source
(https://cs.android.com/search?
q=file:androidx/core/splashscreen/SplashScreen.kt+class:androidx.core.splashscreen.SplashScreen)
Added in 1.0.0 (/jetpack/androidx/releases/core#1.0.0)
Kotlin | Java (/reference/androidx/core/splashscreen/SplashScreen)

class SplashScreen (/reference/kotlin/androidx/core/splashscreen/SplashScreen)

Provides control over the splash screen once the application is started.

On API 31+ (Android 12+) this class calls the platform methods.

Prior API 31, the platform behavior is replicated with the exception of the Animated Vector
Drawable support on the launch screen.

Usage of the core-splashscreen


library:
To replicate the splash screen behavior from Android 12 on older APIs the following steps
need to be taken:

1. Create a new Theme (e.g Theme.App.Starting ) and set its parent to


Theme.SplashScreen or Theme.SplashScreen.IconBackground

2. In your manifest, set the theme attribute of the whole <application> or just the
starting <activity> to Theme.App.Starting

3. In the onCreate method the starting activity, call installSplashScreen


(/reference/kotlin/androidx/core/splashscreen/SplashScreen#
(android.app.Activity).installSplashScreen())
just before super.onCreate() . You also need to make sure that
postSplashScreenTheme is set to the application's theme. Alternatively, this call can

https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen 1/7
8/9/24, 10:30 AM SplashScreen | Android Developers

be replaced by Activity#setTheme if a SplashScreen


(/reference/kotlin/androidx/core/splashscreen/SplashScreen) instance isn't needed.

Themes
The library provides two themes: R.style.Theme_SplashScreen
(/reference/kotlin/androidx/core/splashscreen/R.style#Theme_SplashScreen()) and
R.style.Theme_SplashScreen_IconBackground
(/reference/kotlin/androidx/core/splashscreen/R.style#Theme_SplashScreen_IconBackground()) . If
you wish to display a background right under your icon, the later needs to be used. This
ensure that the scale and masking of the icon are similar to the Android 12 Splash Screen.

windowSplashScreenAnimatedIcon : The splash screen icon. On API 31+ it can be an


animated vector drawable.

windowSplashScreenAnimationDuration : Duration of the Animated Icon Animation. The


value needs to be 0 if the icon is animated.

Note: This has no impact on the time during which the splash screen is displayed and is
only used in SplashScreenViewProvider.iconAnimationDurationMillis
(/reference/kotlin/androidx/core/splashscreen/SplashScreenViewProvider#iconAnimationDurationMilli
s())
. If you need to display the splash screen for a longer time, you can use
SplashScreen.setKeepOnScreenCondition
(/reference/kotlin/androidx/core/splashscreen/SplashScreen#setKeepOnScreenCondition(androidx.co
re.splashscreen.SplashScreen.KeepOnScreenCondition))

windowSplashScreenIconBackgroundColor : To be used in with


Theme.SplashScreen.IconBackground . Sets a background color under the splash
screen icon.

windowSplashScreenBackground : Background color of the splash screen. Defaults to the


theme's ?attr/colorBackground .

postSplashScreenTheme * Theme to apply to the Activity when installSplashScreen


(/reference/kotlin/androidx/core/splashscreen/SplashScreen#
(android.app.Activity).installSplashScreen())
is called.

Known incompatibilities:

https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen 2/7
8/9/24, 10:30 AM SplashScreen | Android Developers

On API < 31, windowSplashScreenAnimatedIcon cannot be animated. If you want to


provide an animated icon for API 31+ and a still icon for API <31, you can do so by
overriding the still icon with an animated vector drawable in res/drawable-v31 .

On API < 31, if the value of windowSplashScreenAnimatedIcon is an adaptive icon


(http://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive) , it will be
cropped and scaled. The workaround is to respectively assign
windowSplashScreenAnimatedIcon and
windowSplashScreenIconBackgroundColor to the values of the adaptive icon
foreground and background .

On API 21-22, The icon isn't displayed until the application starts, only the
background is visible.

Design
The splash screen icon uses the same specifications as Adaptive Icons
(https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive) . This means
that the icon needs to fit within a circle whose diameter is 2/3 the size of the icon. The
actual values don't really matter if you use a vector icon.

Specs
With icon background ( Theme.SplashScreen.IconBackground )

Image Size: 240x240 dp

Inner Circle diameter: 160 dp

Without icon background ( Theme.SplashScreen )

Image size: 288x288 dp

Inner circle diameter: 192 dp

Example: if the full size of the image is 300dp*300dp, the icon needs to fit within a circle
with a diameter of 200dp. Everything outside the circle will be invisible (masked).

Summary

https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen 3/7
8/9/24, 10:30 AM SplashScreen | Android Developers

Nested types

fun interface SplashScreen.KeepOnScreenCondition (/reference/kotlin/androidx/core/splash

Condition evaluated to check if the splash screen should remain on screen

fun interface SplashScreen.OnExitAnimationListener (/reference/kotlin/androidx/core/spla

Listener to be passed in SplashScreen.setOnExitAnimationListener


(/reference/kotlin/androidx/core/splashscreen/SplashScreen#setOnExitAnimationListener(androidx.cor
.

Public companion functions

SplashScreen Activity (https://developer.android.com


(/reference/kotlin/androidx/core/splashscreen/SplashScreen).installSplashScreen
(/reference/kotlin/androidx/core/splashsc
(android.app.Activity).installSplashScreen
()

Creates a SplashScreen
(/reference/kotlin/androidx/core/splashsc
associated with this Activity
(https://developer.android.com/reference
setting the theme to R.attr.postSplas
(/reference/kotlin/androidx/core/splashsc
.

Public functions

Unit setKeepOnScreenCondition
(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/- (/reference/kotlin/androidx/core/splashscreen/Splash
unit/index.html) (condition: SplashScreen.KeepOnScreenCon

Sets the condition to keep the splash screen visible.

Unit setOnExitAnimationListener
(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/- (/reference/kotlin/androidx/core/splashscreen/Splash
unit/index.html) (

https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen 4/7
8/9/24, 10:30 AM SplashScreen | Android Developers

Public functions

listener: SplashScreen.OnExitAnimati
)

Sets a listener that will be called when the splashscre

Public companion functions

installSplashScreen Artifact: androidx.core:core-splashscreen (/jetpack/androidx/releases/core)


View Source
(https://cs.android.com/search?
q=file:androidx/core/splashscreen/SplashScreen.kt+function:installSplash
Screen)
Added in 1.0.0 (/jetpack/androidx/releases/core#1.0.0)

fun Activity (https://developer.android.com/reference/android/app/Activity.html).installSplashS

Creates a SplashScreen (/reference/kotlin/androidx/core/splashscreen/SplashScreen) instance


associated with this Activity (https://developer.android.com/reference/android/app/Activity.html)
and handles setting the theme to R.attr.postSplashScreenTheme
(/reference/kotlin/androidx/core/splashscreen/R.attr#postSplashScreenTheme()) .

This needs to be called before Activity.setContentView


(https://developer.android.com/reference/android/app/Activity.html#setContentView(kotlin.Int)) or
other view operations on the root view (e.g setting flags).

Alternatively, if a SplashScreen (/reference/kotlin/androidx/core/splashscreen/SplashScreen)


instance is not required, the theme can manually be set using Activity.setTheme
(https://developer.android.com/reference/android/app/Activity.html#setTheme(kotlin.Int)) .

Public functions

https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen 5/7
8/9/24, 10:30 AM SplashScreen | Android Developers

setKeepOnScreenCondition Added in 1.0.0 (/jetpack/androidx/releases/core#1.0.0)

fun setKeepOnScreenCondition (/reference/kotlin/androidx/core/splashscreen/SplashScreen#setK

Sets the condition to keep the splash screen visible.

The splash will stay visible until the condition isn't met anymore. The condition is
evaluated before each request to draw the application, so it needs to be fast to avoid
blocking the UI.

Parameters

condition: SplashScreen.KeepOnScreenCondition The condition ev


(/reference/kotlin/androidx/core/splashscreen/SplashScreen.KeepOnScreenCondition)decide whether
splash screen on

setOnExitAnimationListener Added in 1.0.0 (/jetpack/androidx/releases/core#1.0.0)

fun setOnExitAnimationListener (/reference/kotlin/androidx/core/splashscreen/SplashScreen#s


listener: SplashScreen.OnExitAnimationListener (/reference/kotlin/androidx/core/spla
): Unit (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)

Sets a listener that will be called when the splashscreen is ready to be removed.

If a listener is set, the splashscreen won't be automatically removed and the application
needs to manually call SplashScreenViewProvider.remove
(/reference/kotlin/androidx/core/splashscreen/SplashScreenViewProvider#remove()) .

IF no listener is set, the splashscreen will be automatically removed once the app is ready
to draw.

The listener will be called on the ui thread.

https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen 6/7
8/9/24, 10:30 AM SplashScreen | Android Developers

Parameters

listener: SplashScreen.OnExitAnimationListener The OnExitAni


(/reference/kotlin/androidx/core/splashscreen/SplashScreen.OnExitAnimationListener) (/reference/kotl
that will be calle

See also

setKeepOnScreenCondition
(/reference/kotlin/androidx/core/splashscreen/SplashScreen#setKeepOnScreenCondition(androidx.cor

SplashScreen.OnExitAnimationListener (/reference/kotlin/androidx/core/splashscreen/SplashSc

SplashScreenViewProvider (/reference/kotlin/androidx/core/splashscreen/SplashScreenViewProvid

Content and code samples on this page are subject to the licenses described in the Content License
(/license). Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2024-06-18 UTC.

https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen 7/7

You might also like