Android doesn't have a built in method of displaying an image at launch like iOS does however there are some techniques we can use to achieve a similar goal.
Modifying the AIR SDK
The simplest method to give your AIR application a splash screen on Android is to change the theme of the main AIR activity to contain an image and a background colour.
This method generally requires no modification to your application code, however you will have to modify your version of the AIR SDK.
To get started open up the AIR SDK
styles.xml file located at
This file should contain the following:
To start, remove
android:windowContentOverlay and add a
android:windowBackground as below:
This will set a
splash_background resource as the background. Lets create this resource by adding a
splash_background.xml file at the following location:
This is where we will create the background for your application which will appear as the splasg screen.
To revert your changes you simply revert the
styles.xml to the original contents above.
Centered Application Icon
A simple splash screen is to use your application icon and center it in the view with a background colour.
Add the following content to the
We will define the background colour in the
colors.xml located at
Change this background colour to suit your application.
Once you've made these changes to the AIR SDK any Android application that is built with this AIR SDK will display your splash screen.
Alternatively if you want to use a custom image as the splash screen you can add an image file to the resources to use as the background.
For example lets add a
splash_image.png to the
drawable directory (alongside
splash_background.xml), you then need to modify
splash_background.xml to use this image as below:
When using this method we advise that you add all the different dpi versions of your image to correctly support different screen sizes: Read more here: https://developer.android.com/guide/practices/screens_support.html
Resources in ANEs
It is possible to to package your splash screen in a Custom Resources ANE. This has the advantage of being able to modify the SDK once and then use a custom ANE to specify the splash screen for each of your applications, rather than have to modify the AIR SDK before each build.
This is done by setting up a default splash screen drawable resource in your AIR SDK and then overriding this resource with resources packaged in the ANE. Normally this would result in a resource conflict however we can use a small trick here. By providing a non resolution specific drawable resource in the AIR SDK and then overriding it with resolution specific versions.
AIR SDK Modifications
Lets start by again adjusting the AIR SDK by specifying a
splash_background resource in the
styles.xml resource located at
Then lets create a fallback resource a simple 1x1 pixel black png called
splash_background.png and place it in the AIR SDK at
AIRSDK/lib/android/lib/resources/app_entry/res/drawable/splash_background.png. This is the resource that will be used if we don't package an ANE containing the override resource.
You should find your AIR SDK packages normally and start with the expected black screen before loading your SWF.
Next lets create the actual resource we will use for the splash in the ANE. You can use the same methods as above however instead of placing the drawable resource in
drawable place a version in each of the resolution specific directories:
This is the important step! If you included the resource in the
drawabledirectory your resource would conflict with the resource created in the AIR SDK and it will fail to package. However adding it to the resolution specific directories means it can override the AIR SDK resource without causing any issues.
This small trick was pointed out by mfrasier on the Starling forum.
You can use a simple stretched image
drawable-hdpi/splash_background.png, a 9-patch png
drawable-hdpi/splash_background.9.png, or an xml resource
We most commonly use the xml method, including another image that is centered in the layout as a drawable:
A VectorDrawable is a vector graphic defined in an XML file as a set of points, lines, and curves along with its associated color information. You can use vector drawables in your splash screen. It was introduced in Android 5.0 (API 21).
We have run into some issues with getting them to scale when centered on Android API < 23, but the process we used is outlined below.
Firstly create your vector drawable resource in the
drawable directory (
splash_icon.xml, for example this renders the battery charging image from the Android Guide:
Then to use this in your splash screen, change your
splash_background.xml file to the below:
Using this method you can create fairly complex scalable images without adding much to your application.
This was generated from the following vector drawable xml: