Android Studio: Splash Screen Tutorial

How to create splash screen using JAVA Programming Language

Published: May 17, 2020




This Tutorial help to you create a simple Splash Screen Tutorial. Following and copy this code simple Layout on XML file.


activity_splash_screen.xml
<?xmlversion="1.0" encoding="utf-8"?> <FrameLayout 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_heigh="match_parent" tools:context=".SplashScreen"> <ImageView android:layout_width="match_parent" android:layout_width="match_parent" android:background="@drawable/splash_img" android:layout_gravity="center"/> </FrameLayout>
styles.xml

Follow and copy the code to remove the Title action bar on the activity

<style name="AppTheme.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> </style>

SplashScreen.java

Place StartSplash(); function inside onCreate

StartSplash();

Follow and copy the StartSplash(); function

protected void StartSplash(){ /** set the time to splash out */ final int welcomeScreenDisplay = 3500; Thread splashTimer = new Thread (){ int wait = 0; @Override public void run(){ try{ super.run(); /** use while go to get the splash time. Use sleep() to increase the wait variable for every 100l */ while (wait < welcomeScreenDisplay){ sleep(100); wait +=100; } }catch (Exception e){ System.out.println("EXc="+e); }finally { /** Called after splash times up. Do some action after splash here times up. Here we moved to another main activity class * */ startActivity(new Intent(SplashScreen.this, MainActivity.class)); finish(); } }; splashTimer.start(); }

You can Download the source on GitHub and Follow the full video tutorial on YouTube. Don't forget to subscribe to the YouTube channel for more updates.


Download at GitHub Visit on YouTube

I will post again on this site and upload on YouTube about my next tutorial. Stay tune up and follow my other social media platforms for more updates.