How to implement Splash Screen in Android studio
Android Apps uses Android Splash Screen before launching application Activity. Android splash screen is used to display a logo or brand for an app. In this article we are going to discuss about implementing an Android Splash Screen in a simple manner.
Android Splash Screen:First we will create a new default project using these simple steps:
- Click on File > New Project.
- Next, define Application Name and Minimum SDK and hit Next
- Select Blank Activity and Hit Next.
- Hit Finish.
You need to define the spash screen in your activity_splash_screen.xml
file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/splashscreen"
android:layout_width="wrap_content"
android:layout_height="match_parent" android:src="@drawable/Splash_image"
android:layout_gravity="center"/>
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Hello World, splash"/>
</LinearLayout>
SplashScreen Class:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends AppCompatActivity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 1000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) ) {
super.onCreate(savedInstanceState) );
setContentView(R.layout.activity_splash_screen);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent intnt_home= new Intent(Splash.this,Home.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}
Another Home Activity:
You need to define the Home Activity in your activity_home.xml
file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Hello World, Home"/>
</LinearLayout>
Home Class:
public class Home extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) ) {
super.onCreate(savedInstanceState) );
setContentView(R.layout.activity_home);
}
You need to define the spash screen in your
activity_splash_screen.xml
file.<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/splashscreen"
android:layout_width="wrap_content"
android:layout_height="match_parent" android:src="@drawable/Splash_image"
android:layout_gravity="center"/>
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Hello World, splash"/>
</LinearLayout>
SplashScreen Class:import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends AppCompatActivity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 1000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) ) {
super.onCreate(savedInstanceState) );
setContentView(R.layout.activity_splash_screen);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent intnt_home= new Intent(Splash.this,Home.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}
Another Home Activity:You need to define the Home Activity in your
activity_home.xml
file.<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Hello World, Home"/>
</LinearLayout>
Home Class:
public class Home extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) ) {
super.onCreate(savedInstanceState) );
setContentView(R.layout.activity_home);
}
Post a Comment