Hello everyone today i will show you how to create a splash screen in android.
This is one of the simplest ways to create a splash screen however there are another ways to create the splash screen.
Lets look at the code.
We need two layouts one for the splash screen and another for the first screen that comes after splash screen.
The splash screen layout will look like this.
splashscreen.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:src="@drawable/android" android:layout_width="fill_parent" android:id="@+id/imageView1" android:layout_height="fill_parent"></ImageView> </LinearLayout>
Now the main.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="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Splash screen Demo from CoderzHeaven" /> </LinearLayout>
Now the main java file.
package pack.coderzheaven; import android.app.Activity; import android.os.Bundle; import android.os.CountDownTimer; public class SplashScreenDemo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splashscreen); creatingSplashScreen(); } private void createFirstScreen() { setContentView(R.layout.main); } private void creatingSplashScreen() { new CountDownTimer(5000, 1000) { public void onTick(long millisUntilFinished) { } public void onFinish() { createFirstScreen(); } }.start(); } }
Make sure you have an image named “android.png” or “android.jpg” in your res/drawable folder.
Great tutorial worked perfectly code is nice and small as compared to Thread Concept,this concept was nice.
Create the Virtual Device with high Virtual Memory heap size, this will solve the outofmemory problem.
Great tutorial easier than the Thread concepts
Is it Possible to place some button in the main.xml and can be proceeded with that???
Cos i tried keeping a Button in main.xml which will lead to another Screen(3rd page), but tat gives a Force Close.
(Splashscree—>main—->screen3 = gives a Force Close)
Check the Logcat for the reason of force close.
or paste that error here so that I can look.
So,I should write codes in createFirstScreen() for my MainActivity,is that right?
Yes, you are right Follen.
after so many days of searching, i finally found the most simple and working one..thanks a lot
Very nice dude…
I have also found one good link here….
Splash screen – Android Example