diff --git a/README.md b/README.md new file mode 100644 index 0000000..07ad9ed --- /dev/null +++ b/README.md @@ -0,0 +1,201 @@ +# How to create a Splash screen + +##### Well, actually, it's easy. The ingredients are: + +* An Activity for the Splash Screen (without the layout file) +* Your Manifest: to declare you Splash Screen as the Launcher +* One drawable(logo) file to customize the splash screen a little + + *The splash view has to be ready immediately, even before you can inflate a layout file in your splash activity.* + + +# Api's Used + +For making our splash screen more attractive and more real, I used two animation api's to ehnhance the look. The api's are [com.daimajia.androidanimations:library](https://github.com/daimajia/AnimationEasingFunctions) and [com.airbnb.android:lottie](https://github.com/airbnb/lottie-android). So, lets get started on adding the dependencies. + +## The recipe: + +## Step 1 (Adding dependencies) +### Android Animations Library +#### Gradle +```groovy +dependencies { + implementation 'com.daimajia.androidanimations:library:2.3@aar' +} +``` +#### Maven + +```xml + + com.android.support + support-compat + 25.1.1 + + + com.daimajia.androidanimation + library + 2.3 + + + com.daimajia.easing + library + 2.0 + +``` +### Android Lottie +#### Gradle +Gradle is the only supported build configuration, so just add the dependency to your project `build.gradle` file: + +```groovy +dependencies { + implementation 'com.airbnb.android:lottie:$lottieVersion' +} +``` +The latest Lottie version is: +![lottieVersion](https://maven-badges.herokuapp.com/maven-central/com.airbnb.android/lottie/badge.svg) + +Lottie 2.8.0 and above only supports projects that have been migrated to [androidx](https://developer.android.com/jetpack/androidx/). For more information, read Google's [migration guide](https://developer.android.com/jetpack/androidx/migrate). + +## Step 2 + +###### Create your Splash Screen Activity + +```java +public class SplashActivity extends Activity { + //This is the time it will take for the splash screen to be displayed + private static int SPLASH_TIME_OUT = 3000; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_splash); + + //This is where we change our app name font to blacklist font + Typeface typeface = ResourcesCompat.getFont(this, R.font.blacklist); + + TextView appname= findViewById(R.id.appname); + appname.setTypeface(typeface); + + // We use the Yoyo to make our app logo to bounce app and down. + //There is a lot of Attension Techniques styles + // example Flash, Pulse, RubberBand, Shake, Swing, Wobble, Bounce, Tada, StandUp, Wave. + // Your can change the techniques to fit your liking. + YoYo.with(Techniques.Bounce) + .duration(7000) + .playOn(findViewById(R.id.logo)); + + //This is where we make our app name fade in as it moves up + // There are other Fade Techniques too + //example FadeIn, FadeInUp, FadeInDown, FadeInLeft, FadeInRight + //FadeOut, FadeOutDown, FadeOutLeft, FadeOutRight, FadeOutUp + YoYo.with(Techniques.FadeInUp) + .duration(5000) + .playOn(findViewById(R.id.appname)); + + new Handler().postDelayed(new Runnable() { + + /* + * Showing splash screen with a timer. This will be useful when you + * want to show case your app logo / company + */ + + @Override + public void run() { + // This method will be executed once the timer is over + // Start your app main activity + startActivity(new Intent(SplashActivity.this,WelcomeActivity.class)); + finish(); + } + }, SPLASH_TIME_OUT); + } +} + +``` + +activity_splash.xml + +```xml + + + + + + + + + + + + + + + + +``` + +and your Manifest should look something like this + +```xml + + + + + + + + + + + + + + + +``` + + +That is it. You can clone the project using Android Studio and have fun. +Dont forget to follow me for more projects. +