Saturday, 26 April 2014

Creating Splash Screen

Java File : SplashScreen

public class SplashScreen extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 1000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        new Handler().postDelayed(new Runnable() {        
            @Override
            public void run() {
                Intent i = new Intent(SplashScreen.this, SecondScreen.class);
                startActivity(i);
                finish();
            }
        }, SPLASH_TIME_OUT);
    }

}


XML File :activity_splash

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splash3" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="10dp"
        android:gravity="center_horizontal"
        android:text="@string/first_screen_text"
        android:textColor="#ffffff"
        android:textSize="16sp" />

    <ImageView
        android:id="@+id/imgLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="116dp"
        android:contentDescription="@string/logo"
        android:src="@drawable/icon" />
    
</RelativeLayout>

No comments:

Post a Comment