Saturday, July 24, 2021

How to make GIF Splash Screen In Android Studio

We will make gif splash screen in android studio in today’s example.

You can make really great animated and attractive splash screen with GIF.

GIF provides seamless animation to the first impression of any android application.

Traditionally, we were making splash screen with static image.

Static Image may contain company name, logo, slogan etc. information.

There are some third party libraries available on the Github to make some cool animations with splash screen.

We were using those libraries before the concept of GIF was introduced.

Step 1. Library

This project requires third party library to show the gif file in xml layout file.

We will use this github library : android-gif-drawable

Write below line in the build.gradle(Module: app) file

implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'


Step 2. Full Screen Activity
It looks great if your splash screen have full screen mode.

To make an android studio activity as a full screen, we have to change the style of our activity.

Add below source code in styles.xml file

<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
 </style>
Full source code for styles.xml file is as below

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>
</resources>
Now add the following line in the AndroidManifest.xml file under <activity> tag
android:theme="@style/AppFullScreenTheme"

Above line is setting our custom theme which we have just written in the styles.xml file.

So the final source code for AndroidManifest.xml file is as below

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.parsaniahardik.splashgifanimated">

    <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/AppTheme">

        <activity android:name=".MainActivity"

            android:theme="@style/AppFullScreenTheme">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <activity android:name=".WelcomActivity"></activity>

    </application>

</manifest> 

Step 3. WelcomActivity

First of all, we will create a new activity from now.

Keep the name of the new activity as Welcom Activity. It will be our first activity after splash screen has finished it’s loading.

Add the below code in activity_welcom.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".WelcomActivity">

    <TextView

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="Your First Activity After Splash Screen"

        android:layout_marginTop="30dp"

        android:layout_marginLeft="20dp"

        android:textSize="30sp"

         />

</LinearLayout>

 Write down below line in WelcomActivity.java file

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

public class WelcomActivity extends AppCompatActivity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_welcom);

    }

}

 Step 3. Saving GIF file

Obviously we need to have one gif file to load it on the android display screen.

Step 4. Main Activity Changes

Now it is time to play with GIF file.

Add following code to make a gif widget in activity_main.xml

<pl.droidsonroids.gif.GifImageView

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:src="@drawable/androidgif"

        android:scaleType="fitXY"/>

Final code for activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity">

    <pl.droidsonroids.gif.GifImageView

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:src="@drawable/androidgif"

        android:scaleType="fitXY"/>

</android.support.constraint.ConstraintLayout>

We will do this task from the MainActivity.java file


Following is the source code for the MainActivity.java file

import android.content.Intent;

import android.os.Handler;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    /** Duration of wait **/

    private final int SPLASH_DISPLAY_LENGTH = 5000; //splash screen will be shown for 2 seconds

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle icicle) {

        super.onCreate(icicle);

        setContentView(R.layout.activity_main);

        new Handler().postDelayed(new Runnable() {

            @Override

            public void run() {

                Intent mainIntent = new Intent(MainActivity.this, WelcomActivity.class);

                startActivity(mainIntent);

                finish();

            }

        }, SPLASH_DISPLAY_LENGTH);

    }

Read the below coding lines

 new Handler().postDelayed(new Runnable() {

            @Override

            public void run() {

                Intent mainIntent = new Intent(MainActivity.this, WelcomActivity.class);

                startActivity(mainIntent);

                finish();

            }

        }, SPLASH_DISPLAY_LENGTH); 

4 comments:

  1. Very well written about GIF Splash Screen. If you want videos of GIF Splash Screen, please download Vidmate app. vidmate app is a popular video download application, it is a great resource if you want to download videos in languages other than Hindi as well, you can use this app in your chosen language. You can download videos for free with this app, you can download many movies, songs, and videos. You can also download your favorite movies and songs in the languages of your choice, you can download any HD quality video through this app, this app is a modern way to download full length movies in minutes. You can also download this app and

    ReplyDelete
  2. Very well written about ffpmeg on android. If you want videos from ffpmeg on android, please download Vidmate app. vidmate app video downloading speed is very fast, you can download this app on your mobile phone to download any video from any social site, this app is perfect for all age users. I have many non-stop video streams in this app this app will never hang and using the app your mobile phone will never hang and you can download hd videos in this app for free. Over 2,000 movies, songs, videos you can watch online at any time. Due to its fast video download speed, this app has become the number one video download app all over the world. You can also download ffpmeg on android and vidmate from app 9apps

    ReplyDelete