Help us understand the problem. What is going on with this article?

Create launch/splash screen with fixed sized image and stretched background color on any device

More than 1 year has passed since last update.

We demonstrate here how to add a splash screen to your android application. The splash screen consists of a image which will be have a constant size and remains centered on any device. Depending on your image, we can also fill the device screen with the background color of the image for a continuous splash screen.

Create png of choice (@mipmap/launch_icon)

We choose an icon with a background color that is approximately constant.
evsmart_launch_icon_small.png

Generate 9-patch drawable (@drawable/launch_icon_9_patch)

Open the png in the Android Studio 9-patch editor (right click on image file in the navigator -> select "Create 9-Patch file..."). In this demonstration, we want the image size to be fixed, but the space between the image and edges of the screen filled with the same background color as the image.

Therefore, we define 1-pixel regions on the edge of the image as the stretchable area. The following three regions require this definition:

Top-left corner

Screen Shot 2019-01-15 at 13.07.44.png

Top-right corner

Screen Shot 2019-01-15 at 13.08.12.png

Bottom-left corner

Screen Shot 2019-01-15 at 13.08.23.png

The 9-patch editor viewer should look like the following image, where we see the result of stretching with different patch-scales. The image shows, in vertical order,
i) stretching in vertical direction only,
ii) stretching in horizontal direction only,
iii) stretching in both directions.

On most devices, our launch/splash screen will look like iii).

Screen Shot 2019-01-15 at 13.04.22.png

Create Drawable file containing the 9-patch image (e.g. drawable/launch_screen.xml)

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/launch_screen_image">
        <nine-patch
            android:src="@drawable/launch_icon_9_patch"
            android:dither="true" />
    </item>
</layer-list>

Set drawable as the app theme window background in res/values/styles.xml

<resources>
    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground"> @drawable/launch_screen </item>
    </style>
</resources>

Note: if you have already used the default windowBackground as a color, e.g.

android:background="?android:attr/windowBackground" 

This will no longer work and a specific color will must now be specified.

Ensure app theme set in Manifest file

<manifest>
    <application
        android:theme="@style/AppTheme">
    </application>
</manifest>
cayozin
iOS/Android development (Swift/C++/Java/Kotlin/XML/Javascript), backend (php/mySQL) and Machine Learning (Python/Scala)
ayudante
いつもユーザー中心で技術者とコンサルタントがとことん考え抜く それがアユダンテです
https://ayudante.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした