How To Implement Android Splash Screen {Simple Solution}

Please follow and like us:

Android Splash Screen

Implement Android Splash Screen [Example/Tutorial]

We can use Splash Screen as launcher screen as waiting screen for network operations or we can shows as dummy screen to our app before main screen. We can also add nice animation to splash screen so it doesn’t looks boring to users of app.

 

Create Splash Image and put it into activity_splash.xml file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" tools:context=".SplashActivity">

    <ImageView android:id="@+id/imgSplash" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitXY" android:src="@drawable/nk_png" />

</LinearLayout>

Splash Activity.java contains main logic of implementing Android Splash Screen.

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;

public class SplashActivity extends AppCompatActivity {

    private ImageView imgSplash;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        imgSplash = (ImageView) findViewById(R.id.imgSplash);


        AnimationSet animation = new AnimationSet(true);
        animation.addAnimation(new AlphaAnimation(0.0F, 1.0F));
        animation.addAnimation(new ScaleAnimation(0.0f, 1, 0.0f, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f)); // Change args as desired
        animation.setDuration(1500);

        imgSplash.startAnimation(animation);

        new CountDownTimer(5000, 1000) {

            public void onTick(long millisUntilFinished) {

            }

            public void onFinish() {


                Intent i = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(i);
                finish();
            }
        }.start();
    }
}

We used countdown timer for 5 seconds here, but you can perform network operations also there, hope you liked out “implement android splash screen” simple tutorial, if you find any difficulty to implement android splash screen example in your app then let me know via comment here, glad to help you.

 

Stay connected for latest android development tutorials for beginners.

nirav kalola