How to make advance e-commerce grocery android app in 2021-2022 (Part 1) | Intro & Splash Screen

In this video series, we will learn how to build advanced Ecommerce android app in android studio. this tutorial series is in the Hindi language. So this is the first video of this tutorial series in which we will learn to build a splash screen for our android app. there are many ways to make a splash screen for the app. but we used the most recommended way to make a splash screen. please watch full video to understand what you will learn in this tutorial series and how to make the splash screen of the android app.

Best Way to Make Splash Screen In Android Studio

Before I tell you how to make a splash screen I highly recommend you to watch a video tutorial in which we explain everything in detail. The purpose of writing this article is to share code with you that we wrote to build a splash screen. 

To make a splash screen in the android studio first step is to Create A New Project in the android studio and select the Default language Java because we are going to use the java programming language throughout this tutorial series. and you should select minimum android API level 21. 

After Creating Project you will see MainActivity.java file and its XML file. every time we create a new project android studio creates this activity for us.   

So now we will create a New Activity and we will set its name SplashActivity and put below code in that activity 

package com.exammm.suppercart;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                 // this code will run after 2 seconds
                startActivity(new Intent(SplashActivity.this,MainActivity.class));
            }
        };
        new Handler().postDelayed(runnable,2000);
    }
}

As you can see in above code we have used Runnable and handler with postDlayed to run startActivity code after 2 seconds. after two second user will navigate from splash activity to main activity

Create Style For Splash Activity

Now its time to add logo in our splash activity to set logo we will create a style in themes.xml file if you are using old android studio version then you will need to open styles.xml file bellow you can see our style code

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.SupperCart" parent="Theme.MaterialComponents.DayNight.NoActionBar">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/white</item>
        <item name="colorPrimaryVariant">@color/colorPrimaryDark</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/color_accent</item>
        <item name="colorSecondaryVariant">@color/color_accent_dark</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>



    // this theme is for Splash Activity

    <style name="SplashTheme" parent="Theme.SupperCart">
        <item name="android:windowBackground">@drawable/splash_background</item>
    </style>

</resources>

As you can see in above code we have created a style by name SplashTheme and we set its parent Theme.SupperCart which is our main style of our app.

in SplashTheme we set android:windowBackground and here we have provided slash_background Drawable. 

Create splash_background Drawable File.

in this section we will create a splash_background drawable and we will use layer_list and two items in that drawable one is for splash activity background color and second is for Splash Acitivty Logo image. 

below you can see complete code of splash_background.xml file

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <color android:color="@color/white"/>
</item>
    <item>
        <bitmap android:src="@drawable/spuuercart_200" android:autoMirrored="false" android:gravity="center"/>
    </item>
</layer-list>

In above code you can see for logo we have used bitmap and provided our bitmap image drawable path that is spuuercart_200. You should first add your logo image in drawable with the name

spuuercart_200 other wise you will see an error.

Now last step is to use our splashtheme style for that you will need to open AndroidManifest.xml file and set splash them like this.

  <activity
            android:name=".SplashActivity"
            android:exported="true"
            android:theme="@style/SplashTheme"    // here we have used splash theme
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

Complete code of AndroidManifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.exammm.suppercart">

    <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.SupperCart">
        <activity
            android:name=".SplashActivity"
            android:exported="true"
            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"
            android:exported="true">

        </activity>
    </application>

</manifest>

I hope you understand how to make splash screen or splash activity in android studio if you still have any question or query please ask us in comment section we will be glade to help you 

Happy Coding!

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow