splash screen
tutorial
app development
user interface
programming

How do I make a splash screen?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Creating a splash screen, typically the first thing users see when opening an application, can set the stage for the user experience by providing branding, a loading indicator, or showcasing core functionality. Implementing a splash screen involves multiple components, including design, animation, and handling the application lifecycle. In this guide, we'll explore how to make a splash screen with technical explanations and code examples across various platforms.

What is a Splash Screen?

A splash screen is an introductory screen that appears while an application is launching. It serves several purposes:

  1. Branding: Displaying the app or company logo.
  2. Loading: Indicating that the application is starting up.
  3. User Engagement: Making the first impression with animation or visuals.
  4. Initialization: Preparing the app by pre-loading resources in the background.

Key Elements of a Splash Screen

  • Image/Logo: Central image that represents the brand.
  • Background: Can be a solid color, gradient, or a more complex pattern.
  • Textual Elements: Taglines or App name.
  • Animations: Fade-in/out animations or progress indicators.
  • Duration: Typically lasts a few seconds, or until the app is ready.

Implementing a Splash Screen in Android

In Android, you can implement a splash screen using a combination of layout resources and background threads to manage loading times. Here's a basic guide:

Step 1: Create a Splash Activity

Create an activity dedicated to the splash screen. This activity will host the splash layout and handle navigation to the main app interface.

xml
1<!-- res/layout/activity_splash.xml -->
2<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3    android:layout_width="match_parent"
4    android:layout_height="match_parent"
5    android:orientation="vertical"
6    android:gravity="center"
7    android:background="#FFFFFF">
8
9    <ImageView
10        android:id="@+id/splash_image"
11        android:layout_width="wrap_content"
12        android:layout_height="wrap_content"
13        android:src="@drawable/logo"/>
14
15</LinearLayout>

Step 2: Modify the Splash Activity

Handle the logic for timing and transitioning from the splash screen to the main screen.

java
1// src/com/example/app/SplashActivity.java
2public class SplashActivity extends AppCompatActivity {
3
4    @Override
5    protected void onCreate(Bundle savedInstanceState) {
6        super.onCreate(savedInstanceState);
7        setContentView(R.layout.activity_splash);
8
9        new Handler().postDelayed(new Runnable() {
10            @Override
11            public void run() {
12                Intent mainIntent = new Intent(SplashActivity.this, MainActivity.class);
13                startActivity(mainIntent);
14                finish();
15            }
16        }, 3000);  // Duration of splash screen: 3 seconds
17    }
18}

Step 3: Update the Manifest

Declare the splash activity in the Android Manifest.

xml
1<!-- AndroidManifest.xml -->
2<activity
3    android:name=".SplashActivity"
4    android:theme="@style/SplashTheme">
5    <intent-filter>
6        <action android:name="android.intent.action.MAIN" />
7        <category android:name="android.intent.category.LAUNCHER" />
8    </intent-filter>
9</activity>

Implementing a Splash Screen in iOS

In iOS, a splash screen is achieved using a Launch Screen storyboard. This is more about ensuring the app loads with a consistent look before transitioning to the first view controller.

Step 1: Create a Launch Screen

  • Open Xcode and add a new file of type Storyboard.
  • Design the splash view in this storyboard with similar elements: image, background color, etc.
xml
1<!-- LaunchStoryboard.storyboard -->
2<view
3    key="view"
4    contentMode="scaleToFill"
5    id="iN0-l3-epB">
6    <subviews>
7        <imageView
8            opaque="NO"
9            clipsSubviews="YES"
10            contentMode="center"
11            image="launchImage"
12            translatesAutoresizingMaskIntoConstraints="NO"
13            id="1">
14        </imageView>
15    </subviews>
16    <color key="backgroundColor" red="0.0" green="0.5" blue="1.0" alpha="1" colorSpace="deviceRGB" />
17</view>

Step 2: Configure the Launch Screen

  • Ensure your Launch Screen is specified in the project's general settings under the "Launch Screen File" setting.
plaintext
Project Settings -> General -> App Icons and Launch Images -> Launch Screen File

Considerations

  • Duration: Use a short, uninterruptible splash unless important initialization tasks are taking place.
  • Feedback: If loading time is substantial, provide feedback (e.g., a loading indicator).
  • Aesthetics: Keep it simple yet aligned with your brand visual identity.

Comparison Table

FeatureAndroidiOS
Layout DefinitionXML LayoutStoryboard
TimingHandler or CoroutineControlled by system (as short as possible)
TransitionExplicit activity switchAutomatically switches to the initial view controller
AnimationsProgrammatically with View APIsLimited, typically set in the main application code

Advanced Topics

  • Dynamic Splash Screens: Use server-side data to dynamically update the splash screen.
  • Accessibility: Ensure that splash screens are short to avoid frustration and adhere to accessibility standards.

By following these steps, you will be able to create a functional and engaging splash screen that enhances your application’s user experience. Remember, while aesthetics are important, functionality and performance should always remain a priority.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions