Tuesday, 28 September 2021

Splash Screen

Here we are making splash screen which is used in all application as a first screen.

So lets start to learn how to make the splash screen.

First make .xml layout for it , most of splash screen are with image.

So here is your splash_screen.xml 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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_height="match_parent">

<ImageView
    android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
tools:srcCompat="@mipmap/ic_launcher" />
</LinearLayout>


Now , next is you have to make Splash.java 

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;


public class Splash extends Activity {

private static int SPLASH_SCREEN_TIME_OUT=3000;
//when 3000 ms(milli seconds) complete, the next activity will get started.


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.splash_screen);


new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i=new Intent(Splash.this, MainActivity.class);
startActivity(i);

finish();

}
}, SPLASH_SCREEN_TIME_OUT);
}
}

So , This is the how with little lines of code we make splash screen for all applications.

No comments:

Post a Comment

Comments

Find Hours Diffrence in Kotlin

  In Kotlin, determining the difference in hours between two timestamps is a common task, especially in scenarios involving time-based calcu...