TechBuzzPro

How to Create a Splash Screen with Layer List in Android

· 7 min read · Phones & Tablets

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To create a splash screen with a layer list in Android, you define an XML drawable using the <layer-list> element, set it as the window background of your launcher activity, and optionally switch to the official SplashScreen API for Android 12 and higher. The layer list approach is lightweight, works on all API levels, and avoids the white flash that appears before your first activity renders. This guide walks you through the classic method step by step, explains how it interacts with the modern SplashScreen API, and covers common pitfalls.

What You'll Need

  • Android Studio with a project targeting at least API 21 (the layer list itself works on older versions, but the SplashScreen API needs API 31+).
  • A launcher activity already declared in your manifest.
  • Basic familiarity with XML drawables and the res/drawable folder.
  • Optional: a logo image (PNG or vector) to place in the center of the splash screen.

Step-by-Step

  1. Create the layer list drawable. In Android Studio, right-click res/drawable, choose New > Drawable Resource File, name it splash_background.xml, and set the root element to layer-list. If you prefer to write it manually, create the file with this structure:
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@color/your_background_color" />
        <item>
            <bitmap
                android:gravity="center"
                android:src="@drawable/your_logo" />
        </item>
    </layer-list>
    The first <item> fills the screen with a solid color; the second centers your logo. You can add more layers (for example, a gradient or a bottom-aligned branding strip) by adding additional <item> elements. The order matters: later items are drawn on top.
  2. Define the background color. If you referenced @color/your_background_color, make sure it exists in res/values/colors.xml. For example: <color name="your_background_color">#FFFFFF</color>. Using a color resource keeps the splash consistent with your theme.
  3. Create a dedicated theme for the launcher activity. In res/values/themes.xml (or styles.xml), add a theme that sets android:windowBackground to your layer list drawable. For example:
    <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_background</item>
        <item name="android:windowNoTitle">true</item>
    </style>
    If you are using Material Components, parent can be Theme.MaterialComponents.Light.NoActionBar. The exact parent theme depends on your app; labels and attributes can differ slightly by version, device, or region, so verify against your project's existing theme.
  4. Apply the theme to your launcher activity in the manifest. Open AndroidManifest.xml and set android:theme="@style/SplashTheme" on the <activity> that has the MAIN and LAUNCHER intent filter. This makes the system use your layer list as the window background before the activity's content view is inflated.
  5. Switch back to your normal theme in onCreate. Before calling setContentView, call setTheme(R.style.AppTheme) (replace AppTheme with your app's main theme). This ensures the rest of the activity uses your regular styling. If you skip this, the splash theme may persist and cause missing action bars or incorrect colors.
  6. Handle the transition. The layer list splash disappears as soon as the activity draws its first frame. If you need to keep it visible while loading data, you can either use a dedicated splash activity that finishes after a delay, or use the official SplashScreen API (see next step). For a simple static splash, the window background method is usually enough.
  7. Consider the official SplashScreen API for Android 12+. On API 31 and higher, the system enforces a splash screen. You can customize it via android:windowSplashScreenBackground and android:windowSplashScreenAnimatedIcon in your theme, or by using the SplashScreen compat library. The layer list approach still works as a fallback for older versions. If you use both, make sure the layer list and the SplashScreen API settings are visually consistent to avoid a jarring double splash.
  8. Test on multiple API levels. Run the app on an emulator or device with API 21, API 30, and API 31+ to confirm the splash appears correctly and transitions smoothly. Pay attention to the status bar color and whether the logo is centered on different screen sizes.

Common Mistakes

  • Forgetting to reset the theme. If you don't call setTheme in onCreate, your activity may keep the splash theme, leading to missing action bars or wrong colors.
  • Using a large bitmap without scaling. A high-resolution logo in a layer list can cause memory issues or slow rendering. Use a vector drawable or a properly sized PNG, and consider android:gravity="center" to avoid stretching.
  • Placing the layer list on the wrong activity. The splash theme should be on the launcher activity only. Applying it to all activities will show the splash every time you navigate.
  • Ignoring the Android 12 splash screen. On Android 12+, the system splash screen appears regardless of your layer list. If you don't customize it, users may see two different splash screens. Use the SplashScreen API attributes to align them.
  • Hardcoding colors instead of using resources. This makes it harder to support dark mode or theme changes. Always reference color resources.

Tips

  • Use a vector drawable for your logo to keep the APK size small and ensure crisp rendering at any density.
  • Set android:windowNoTitle to true in the splash theme to avoid a brief action bar flash.
  • If you need a timed splash, create a separate SplashActivity that uses the layer list as its background, then starts your main activity after a short delay. Remember to call finish() so the user can't navigate back to it.
  • Test with dark mode enabled. If your app supports dark theme, provide a separate layer list in drawable-night or use theme attributes like ?attr/colorBackground.
  • Keep the splash simple: a solid background and a centered logo is usually enough. Avoid complex animations in the layer list, as they are not supported.

Troubleshooting

If the splash screen does not appear or looks wrong, check these items in order:

  • White screen instead of splash: Verify that the theme is applied to the correct activity in the manifest and that the drawable file name matches exactly. Also ensure the activity does not call setContentView before the window background is drawn—this is normal, but if you set a content view with an opaque background immediately, it may cover the splash.
  • Splash persists after launch: Make sure you call setTheme(R.style.AppTheme) in onCreate before setContentView. If you use a separate splash activity, ensure it finishes.
  • Logo is stretched or off-center: Use android:gravity="center" on the bitmap item and avoid fixed width/height unless necessary. For vector drawables, set android:width and android:height in the vector file.
  • Android 12+ shows a different splash: The system splash screen takes precedence. Customize it using the windowSplashScreenBackground and windowSplashScreenAnimatedIcon attributes in your theme, or use the SplashScreen compat library. Keep the layer list for older versions.
  • App crashes on launch: Check that the drawable XML is well-formed and that all referenced resources exist. Look at Logcat for InflateException or Resources.NotFoundException.

Frequently Asked Questions

Can I use a layer list for the Android 12 splash screen?

No. Android 12 and higher use the system SplashScreen API, which does not accept a layer list drawable directly. You can set a background color and an icon via theme attributes, but for full control you should use the SplashScreen compat library. The layer list method is best for older versions or as a fallback.

Do I need a separate activity for the splash screen?

Not necessarily. For a static splash that disappears when the first frame draws, setting the window background on your launcher activity is sufficient. If you need to show the splash for a fixed duration or while loading data, a dedicated splash activity is more appropriate.

Why does my splash screen show a white flash before the layer list?

A white flash usually means the window background is not set correctly or the theme is not applied. Double-check the manifest and theme. Also, ensure that your launcher activity does not set a content view with an opaque background before the splash is drawn—this is normal, but if the content view loads instantly, the splash may be barely visible.

Can I animate the layer list splash?

Layer list drawables do not support animations. For animated splashes, use the SplashScreen API on Android 12+ or implement a custom splash activity with an animated drawable or a view-based animation.

How do I support dark mode with a layer list splash?

Create a separate layer list XML in res/drawable-night with a dark background and a light logo, or use theme attributes like ?attr/colorBackground in your layer list. The system will automatically pick the appropriate resource based on the device's dark mode setting.

Is the layer list method still recommended?

For apps targeting Android 12 and above, the official SplashScreen API is recommended because it provides a consistent experience and is enforced by the system. However, the layer list method remains useful for backward compatibility on older devices and is simple to implement.