0 votes
in Other by
How do I make a splash screen?

I wanted to make my app look more professional, so I decided that I wanted to make a splash screen.

How would I create it and then implement it?

1 Answer

0 votes
by
edited by

This answers shows you how to display a splash screen for a fixed amount of time when your app starts for e.g. branding reasons. E.g. you might choose to show the splash screen for 3 seconds. However if you want to show the spash screen for a variable amount of time (e.g. app startup time) you should check out Abdullah's answer https://stackoverflow.com/a/15832037/401025. However be aware that app startup might be very fast on new devices so the user will just see a flash which is bad UX.

First you need to define the spash screen in your layout.xml file

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

  <LinearLayout xmlns:android="""

          android:orientation="vertical" android:layout_width="fill_parent"

          android:layout_height="fill_parent">

          <ImageView android:id="@+id/splashscreen" android:layout_width="wrap_content"

                  android:layout_height="fill_parent"

                  android:src="@drawable/splash"

                  android:layout_gravity="center"/>

          <TextView android:layout_width="fill_parent"

                    android:layout_height="wrap_content"

                    android:text="Hello World, splash"/>

  </LinearLayout>

And your activity:

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.os.Handler;

public class Splash extends Activity {

    /** Duration of wait **/

    private final int SPLASH_DISPLAY_LENGTH = 1000;

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

    @Override

    public void onCreate(Bundle icicle) {

        super.onCreate(icicle);

        setContentView(R.layout.splashscreen);

        /* New Handler to start the Menu-Activity 

         * and close this Splash-Screen after some seconds.*/

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

            @Override

            public void run() {

                /* Create an Intent that will start the Menu-Activity. */

                Intent mainIntent = new Intent(Splash.this,Menu.class);

                Splash.this.startActivity(mainIntent);

                Splash.this.finish();

            }

        }, SPLASH_DISPLAY_LENGTH);

    }

}

Related questions

0 votes
asked Nov 25, 2019 in SOAPUI by rajeshsharma
0 votes
asked Aug 29, 2023 in Android Library by rahuljain1
...