Creating a Splash Screen

A splash screen is mostly a project that opens the first screen of a mobile application. That screen lists images, logos, and others. Generally shows for the first time when an app is launched. The splash screen is used to display basic information on mobile applications.

let's take example of splash screen in Mobile application.

Step by step implementation

Step 1: Create a new project in Android  or you can use an already created project.  


Step 2: Create an activity_main.xml file in your layout folder . path (res>layout)

 implement the same invoke the following code inside activity_main.xml file. 

 <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/idRLContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/company_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

Step 3: Create an MainActivity.java file in your package folder .

 Implement the same invoke the following code inside MainActivity.java file.

 import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
private static final int SPLASH_SCREEN_TIME_OUT = 2000;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main_two);
new Handler().postDelayed(() -> {
Intent i = new Intent(MainActivity.this, MainActivityone.class);
startActivity(i);
finish();
}, SPLASH_SCREEN_TIME_OUT);
}

}
Step 4: Output of above example

Happy coding!

365Bloggy June 4, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive