How to Create Splash Screen | Welcome Screen in Android Studio Episode #009

How to Create Splash Screen

How to Create Splash Screen | Welcome Screen in Android Studio Episode #009

Step 1:

Create a new activity for splash screen. Change ConstraintLayout  to LinearLayout.  Add orientation vertical.

XML Splash Activity

<ImageView
        android:id="@+id/splash"
        android:layout_width="wrap_content"
        android:layout_height="400dp"
        android:src="@drawable/icon"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Please wait!"
            android:textColor="#552999da"
            android:textSize="50dp"
            android:gravity="center"/>

    </LinearLayout>

Step 2:

Add code Splash JAVA file.

ImageView imageView;

imageView = (ImageView) findViewById(R.id.splash);

Animation animation = AnimationUtils.loadAnimation(splash.this, R.anim.animation);
imageView.startAnimation(animation);
Thread td = new Thread() {
                     public void run()
                {
                    try {
                        sleep(3000);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    } finally {
                        Intent it = new Intent(splash.this, MainActivity.class);
                        startActivity(it);
                        finish();
                    }
                }

            };
            td.start();
        }
    }

Step3:

Create on res Folder. Right, Click layout > Go to res>New>Android resource directory. create anim Folder.

animation.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="4000"
        >
</alpha>
</set>

Step 4 :

Step 4 is the last step. Go to Manifest file. Change the placement .mainactivity to the splash screen.

How to Create Splash Screen | Welcome Screen in Android Studio