Android | Creating a Splash Screen
Last Updated :
19 Jan, 2023
A splash screen is mostly the first screen of the app when it is opened. It is a constant screen which appears for a specific amount of time, generally shows for the first time when the app is launched. The Splash screen is used to display some basic introductory information such as the company logo, content, etc just before the app loads completely.
Creating Splash screen using handler in Android
Here we created two activities MainActivity showing the Splash Screen and SecondActivity in order to switch from MainActivity to SecondActivity. The main program is written in MainActivity, you can change activities as per your need.
- To remove the ActionBar, you need to make following changes in your styles.xml file.
style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"
...
- Use colors which is suitable for your application.
- No need to make any changes in your manifest file.
MainActivity.java
Java
package com.example.hp.splashscreen;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Handler;
import android.view.WindowManager;
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);
new Handler().postDelayed( new Runnable() {
@Override
public void run() {
Intent i = new Intent(MainActivity. this , SecondActivity. class );
startActivity(i);
finish();
}
}, SPLASH_SCREEN_TIME_OUT);
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...