1. sylsau's Avatar
    Hello,

    I create that thread to present you a tutorial learning you how to create a Splash Screen on Android by following the right way. Note that you can also discover this tutorial in video on Youtube :



    Create a Splash Screen on Android : the Right Way !

    At a certain moment in the past, Google advised against using a Splash Screen on Android Applications. It was useless. Then, when they have published the Material Design Specifications, some of us have seen that the Splash Screen was now a pattern known as Launch Screen. Ideal to display your brand logo during cold start of applications. So, what’s the difference between the bad Splash Screen and the good Splash Screen ?

    The difference is just the way you implement if. Previously, developers implemented the Splash Screen by displaying their brand logo on the screen during a certain time. The right way to implement a Launch Screen is now just to display your brand logo the time the application starts and no more.

    To create a correct Splash Screen, you need to create a background that will display your brand logo to the screen. For this, you must create an XML file in the res/drawable folder :

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@color/colorPrimary" />
    
        <item>
            <bitmap android:src="@drawable/logo"
                android:gravity="center" />
    
        </item>
    
    </layer-list>
    Next step is to create a dedicated theme for your Splash Activity. For this, you must inherit from the Theme.AppCompat.NoActionBar theme :

    Code:
    <resources>
    
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
        </style>
    
        <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
            <item name="android:windowBackground">@drawable/background</item>
        </style>
    
    </resources>
    Note that your Splash Theme has just to define the android:windowBackground item and set up the background created previously.

    Now, you can create your SplashActivity :

    Code:
    package com.ssaurel.splashscreen;
    
    import android.content.Intent;
    import android.os.Bundle;
    import android.support.annotation.Nullable;
    import android.support.v7.app.AppCompatActivity;
    
    /**
     * Created by ssaurel on 02/12/2016.
     */
    public class SplashActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();
        }
    }
    No need to define a content view for the SplashActivity because you are going to apply the SplashTheme on it. So, you have just to launch the MainActivity of your Android Application and then finish the SplashActivity by calling the finish() method.

    Don’t forget to define your SplashActivity in the Android Manifest and apply the SplashTheme on it :

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.ssaurel.splashscreen">
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
    
            <activity android:name=".SplashActivity" android:theme="@style/SplashTheme">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
    
                </intent-filter>
    
            </activity>
    
            <activity android:name=".MainActivity" />
    
        </application>
    
    </manifest>
    Then, you can write the code of your Android Application in your MainActivity as you want. You can try the application by seeing the demo in the previous video. Now, you could make Splash Screen on Android by following the right way !

    Don't hesitate to give it a try and give me your feedbacks !

    Thanks.

    Sylvain
    B. Diddy likes this.
    12-05-2016 05:55 AM
  2. B. Diddy's Avatar
    Thanks for the tutorial -- you're giving away all of your tricks!
    12-05-2016 01:28 PM
  3. sylsau's Avatar
    Thanks for the tutorial -- you're giving away all of your tricks!
    Yes, it's always good to help new Android developers
    B. Diddy likes this.
    12-06-2016 01:20 AM

Similar Threads

  1. Replies: 4
    Last Post: 12-05-2016, 05:08 PM
  2. Replies: 1
    Last Post: 12-05-2016, 03:42 PM
  3. Where has the torch gone after I updated my Samsung j5 ?
    By AC Question in forum Ask a Question
    Replies: 1
    Last Post: 12-05-2016, 09:08 AM
  4. Calls getting disconnected on my Nexus 6P on LTE
    By AC Question in forum Ask a Question
    Replies: 0
    Last Post: 12-05-2016, 05:04 AM
  5. Android System Development - Global Content/File Filter (More than an app)
    By fabbinde in forum Software Development and Hacking
    Replies: 0
    Last Post: 12-05-2016, 05:02 AM

Tags for this Thread

LINK TO POST COPIED TO CLIPBOARD