Wednesday, 8 October 2014

Splash screen - Android Example

I will show How to make a simple splash screen, it's an activity that will show for set time when your application is starting and after set time period return to application main screen.

Please try it your self.

package com.j4android;


import android.app.Activity;                     

import android.os.Bundle;

public class SplashActivity extends Activity{

@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.main);

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
SplashActivity.this.finish();
Intent i=new Intent(this,MainActivity.class);
           }
}, 4000);
           
       }
}



main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff000"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="SplashScreen"
            android:textColor="#000"
            android:textSize="40dp"
            android:textStyle="bold" />
    </LinearLayout>


</LinearLayout>

No comments:

Post a Comment