in-depth guidelines for the Android splash screen.
A splash screen is a loading screen that appears when you first launch an app. This screen, also known as a launch screen or startup screen, is displayed briefly before the app takes you to the main screen where you can begin using it. The splash screen often displays the company name, logo, and possibly a motto.
There are three common approaches to implementing a splash screen in an app, which are outlined in the following information. Please note that splash screens are usually only displayed briefly and may be easily missed if you look away.
- Using a Launcher Theme (Recommended)
- Splash Screen API (Android 12)
- Using Timers (the old-school style)
Using a Launcher Theme
To create a splash screen using a launcher theme, you will need to follow these steps:
- Create a drawable resource for your splash screen. This should be a high-resolution image that represents your app’s brand or identity.
- Open your app’s manifest file and specify the drawable resource as the value for the “windowBackground” attribute in the “style” element.
- Set the theme of your launch activity to the theme you just created by adding the “android:theme” attribute to the activity element in the manifest file and setting its value to “@style/LauncherTheme”.
- Add a “splash_screen” category to the intent filter for the launch activity in the manifest file. This will ensure that your splash screen is displayed when the app is launched.
- Run your app and test the splash screen to ensure that it is displayed correctly.
Note: It is important to keep in mind that splash screens should not be used to display important information or perform lengthy tasks, as they should only be displayed briefly while the app is loading.
Create a drawable resource for your splash screen –
To create a drawable resource for your splash screen in Android, you will need to follow these steps:
- Open Android Studio and go to the “res” folder in your project directory.
- Right-click on the “drawable” folder and select “New > Drawable resource file”.
- Give your drawable resource a name and select “Drawable” as the resource type. Click “OK”.
- A new XML file will be created in the “drawable” folder. This file will define your drawable resource.
- In the XML file, you can use the “bitmap” element to specify the image file that you want to use as your splash screen. Set the “src” attribute to the name of your image file, which should be located in the “res/drawable” folder.
Here is an example of what the XML file for a splash screen drawable resource might look like:
<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/splash_image" android:gravity="center" />
In this example, “splash_image” is the name of the image file that you want to use as your splash screen. The “gravity” attribute is used to specify that the image should be centered in the window.
- Save the XML file and your splash screen drawable resource will be created. You can then use this resource in your app by specifying it as the value for the “windowBackground” attribute in the “style” element of your app’s manifest file.
Open your app’s manifest file and specify the drawable resource as the value for the “windowBackground” attribute in the “style” element.
To specify the splash screen drawable resource as the value for the “windowBackground” attribute in the “style” element of your app’s manifest file, you will need to add the following line to the “style” element:
android:windowBackground="@drawable/splash_screen"
Replace “splash_screen” with the name of your splash screen drawable resource.
Here is an example of what the “style” element of your manifest file might look like with the “windowBackground” attribute set:
<style name="LauncherTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowBackground">@drawable/splash_screen</item> </style>
In this example, “LauncherTheme” is the name of the theme that you are using for your splash screen, and “splash_screen” is the name of the drawable resource that you want to use as the background.
You will also need to set the theme of your launch activity to the theme you just created by adding the “android:theme” attribute to the activity element in the manifest file and setting its value to “@style/LauncherTheme”.
<activity android:name=".MainActivity" android:theme="@style/LauncherTheme"> ... </activity>
This will ensure that your splash screen is displayed when the app is launched.
Set the theme of your launch activity to the theme you just created by adding the “android:theme” attribute to the activity element in the manifest file and setting its value to “@style/LauncherTheme”.
To set the theme of your launch activity to the theme you created for your splash screen, you will need to add the “android:theme” attribute to the activity element in the manifest file and set its value to “@style/LauncherTheme”.
Here is an example of what the activity element in your manifest file might look like with the “android:theme” attribute set:
<activity android:name=".MainActivity" android:theme="@style/LauncherTheme"> ... </activity>
In this example, “MainActivity” is the name of your launch activity and “LauncherTheme” is the name of the theme that you are using for your splash screen.
This will ensure that your splash screen is displayed when the app is launched. Be sure to also specify the splash screen drawable resource as the value for the “windowBackground” attribute in the “style” element of the manifest file, as described in the previous answer.
Add a “splash_screen” category to the intent filter for the launch activity in the manifest file. This will ensure that your splash screen is displayed when the app is launched.
To add a “splash_screen” category to the intent filter for the launch activity in your app’s manifest file, you will need to add the following line to the “intent-filter” element:
<category android:name="android.intent.category.LAUNCHER" />
Here is an example of what the “intent-filter” element of your manifest file might look like with the “splash_screen” category added:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
In this example, the “action” element specifies that the activity should be launched when the app is launched, and the “category” element specifies that the activity should be displayed as a splash screen.
This will ensure that your splash screen is displayed when the app is launched. Be sure to also specify the splash screen drawable resource as the value for the “windowBackground” attribute in the “style” element of the manifest file, and set the theme of your launch activity to the splash screen theme, as described in previous answers.
Run your app and test the splash screen to ensure that it is displayed correctly.
To test the splash screen in your Android app, you will need to run the app on a device or emulator and observe the initial screen that is displayed when the app is launched.
Here are the steps to run and test your app:
- Connect your Android device to your computer or launch an emulator.
- In Android Studio, click the “Run” button or select “Run > Run ‘app'” from the menu.
- Select your device or emulator from the list of available targets and click “OK”.
- The app will be installed on your device or emulator and launched automatically.
- Observe the initial screen that is displayed when the app is launched. This should be your splash screen.
- If the splash screen is not displayed correctly, or if there are any other issues with the app, you may need to troubleshoot the problem and make necessary adjustments.
- Once you are satisfied with the splash screen, you can continue testing the rest of the app to ensure that it is functioning as expected.
Note: It is important to keep in mind that splash screens should only be displayed briefly while the app is loading. If the splash screen is displayed for too long, it may cause frustration for the user. It is also important to avoid using splash screens to display important information or perform lengthy tasks, as these should be handled in the main screen of the app.
Splash Screen API
Android 12 has introduced a new Splash Screen API which allows apps to display a splash screen with their app symbol at the center when they launch. However, this new feature can cause inconsistency in design and increase user intrusion as the Android 12 default splash screen will be displayed before the app’s splash screen, resulting in two splash screens being shown. To create a more cohesive look and reduce user irritation, it is necessary to add support for Android 12’s splash screen API. This API offers compatibility with previous API levels and also allows for the use of animated icons through AnimatedVectorDrawable or AnimationDrawable. By following the steps provided, you can create an animated splash screen that matches the theme of your device.
Setup
Before you can use the new Splash Screen API in your app, there are a few settings that need to be configured. To ensure compatibility with earlier versions of Android, you will include a splash screen for those releases as well.
1 – To do this, modify the compileSdk in the build.gradle file for your app module and set the Splash Screen API dependency to version 31. For backward compatibility, you should use the compact version.
android { compileSdk = 31 } dependencies { val splahScreenVersion = "1.0.0" // Use: def instead of val if you are not using Kotlin Gradle(.kts) implementation("androidx.core:core-splashscreen:$splashScreenVersion") }
2 – To allow for customization of the theme according to the user’s device’s dark or light mode, create two files called splash theme.xml in the values directory, one in the values directory and the other in the values-night directory. This will make it easier to keep them organized for future updates.
Note: To create the first file, right-click on the values directory and select “New > Values Resource File.” The second file can be created by typing “values-night” into the directory name box. If your project view is set to Android, the values-night directory should be visible.
3 – For both of the files you have created, you will now create the splash screen theme for dark and light mode scenarios. The theme will be called Theme.SplashThemeName will be derived from Theme.SplashScreen. Your files should look like this:
In values/splash_theme.xml:
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:tools="http://schemas.android.com/tools"> <!-- Splash Screen Theme. --> <style name="Theme.AppSplash" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/dark</item> <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher_round</item> <item name="windowSplashScreenAnimationDuration">300</item> <item name="postSplashScreenTheme">@style/Theme.SplishSplash</item> <!-- Status bar and Nav bar configs --> <item name="android:statusBarColor" tools:targetApi="l">@color/dark</item> <item name="android:navigationBarColor">@color/dark</item> <item name="android:windowLightStatusBar">false</item> </style> </resources>
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:tools="http://schemas.android.com/tools"> <!-- Splash Screen Theme. --> <style name="Theme.AppSplash" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/white</item> <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher_round</item> <item name="windowSplashScreenAnimationDuration">300</item> <item name="postSplashScreenTheme">@style/Theme.SplishSplash</item> <!-- Status bar and Nav bar configs --> <item name="android:statusBarColor" tools:targetApi="l">@color/white</item> <item name="android:navigationBarColor">@color/white</item> <item name="android:windowLightStatusBar">true</item> </style> </resources>
The contents of the splash screen are elements that are displayed when an app is first launched. The splash screen typically displays the app’s logo or icon and may also include a loading indicator while the app is loading.
The background color of the splash screen can be set using the windowSplashScreenBackground
attribute. The icon displayed on the splash screen can be set using the windowSplashScreenAnimatedIcon
attribute. It is recommended to use icons with a size of 108dp or smaller to avoid clipping.
The duration of the splash screen can be controlled using the windowSplashScreenAnimationDuration
attribute. This attribute controls how long the splash screen is displayed, but it has no effect on the animation of the icon.
After the splash screen is finished, the app’s actual theme can be specified using the postSplashScreenTheme
attribute. This is where the default app theme should be set.
The status bar
and nav bar
attributes can be used to ensure that the status bar and navigation bar have a consistent theme when the app is launched. These attributes are particularly important for devices running Android API level 30 or lower, as they may display default black bars on the status bar and nav bar if these attributes are not set.
It is important to ensure that the desired settings are entered for both the light and dark modes of the splash screen theme. This will ensure that the splash screen looks consistent in both light and dark modes.
To set the theme of your application to the splash screen theme you previously created, you will need to open the manifest file and set the android:theme
attribute of the <application>
tag to the splash screen theme. You can do this by setting the attribute to @style:Theme.SplashThemeName
, where SplashThemeName
is the name of the splash screen theme you created.
It is important to note that you should delete the android:theme
attribute from the <activity>
tag of your entry activity (the activity with the LAUNCHER
intent) if it already contains the LAUNCHER
intent. If you do not delete this attribute, the app will crash. This is because the standard Android Studio templates usually add the android:theme
attribute to entry activities, and having it present can cause issues. It is important to be aware of this, as it can save you a lot of time and frustration trying to figure out what went wrong.
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.SplashThemeName"> <activity android:name=".ui.main.MainActivity" android:exported="true" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
To use the splash screen in your app, you will need to call the InstallSplashScreen()
method inside the onCreate()
method of your entry activity (the activity that is launched when the app is opened). The InstallSplashScreen()
the method should be called immediately after super.onCreate()
and before setContentView()
.
Here is an example of how you can use the InstallSplashScreen()
the method in your code:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); InstallSplashScreen(); // Call the InstallSplashScreen() method here setContentView(R.layout.activity_main); } }
Now that you have implemented the splash screen, your app should be able to display a splash screen on devices running Android 12 and earlier versions. It is important to note that the icon displayed on the splash screen should not be larger than 108dp, or it will be clipped. The icon can be a drawable, png, jpg, or webp file, but it is not currently possible to use an AnimatedVectorDrawable
or AnimationDrawable
as the splash screen icon on devices running Android versions lower than 12. If you try to use an animated icon on earlier versions, it will not be displayed and the splash screen will show a blank field.
In order to support animated icons on Android 12 and maintain support for earlier versions, it will be necessary to use checks to ensure that the correct icon is displayed. This will be covered in the second chapter of this guide.
Using Timers
In the onCreate()
method of our splash activity, we can create a thread that displays the splash screen for a few seconds (e.g., 2-3 seconds). After the specified time has passed, we can use a timer to navigate to the desired activity. This simple technique allows us to display the splash screen for a brief period of time before transitioning to the main activity of the app. Here is an example of how this technique can be implemented in code:
public class SplashActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); // Start a new thread to display the splash screen for a few seconds new Thread(new Runnable() { @Override public void run() { try { // Show the splash screen for 2-3 seconds Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } finally { // Use a timer to navigate to the desired activity new Timer().schedule(new TimerTask() { @Override public void run() { startActivity(new Intent(SplashActivity.this, MainActivity.class)); finish(); } }, 3000); } } }).start(); } }
In this example, we create a new thread in the onCreate()
method of the splash activity. The thread displays the splash screen for 2 seconds before using a timer to navigate to the MainActivity
after an additional 3 seconds. This allows us to show the splash screen for a total of 5 seconds before transitioning to the main activity of the app.
Splash screen best practice
There are a few best practices to follow when creating a splash screen to ensure that it enhances your brand and provides a pleasant experience for your users. Here are some guidelines to consider:
- Keep the splash screen free of unnecessary distractions. This means using only one color or logo and avoiding the use of too many elements that could clutter the screen.
- Use animation sparingly. While animation can be a useful tool to attract attention and add some visual interest to the splash screen, it is important to use it in moderation. Too much animation can be distracting and may make the splash screen feel cluttered or overwhelming.
Overall, the goal of the splash screen should be to provide a clear and cohesive visual representation of your brand, while also keeping the user engaged and entertained while they wait for the app to load. By following these guidelines, you can create an effective and visually appealing splash screen that enhances the user experience of your app.
Thank you for reading this article. We hope that you found it helpful and informative. If you enjoyed the content and found it useful, please consider giving it a “clap” or recommending it to others. Your support helps us to create more high-quality content like this in the future.
for more information, you can Visit Here. if you want to read our other posts you can check our blog section