Tuesday, December 10, 2013

Android Splash Screen Example

No comments :
Hi,

This is an Example for Splash screen in Android.

1. create a java class called MainActivity.class in Android
 
   MainActivity.java:

 package com.example.game;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;

public class Splash extends Activity
{
private boolean mIsBackButtonPressed;
    private static final int SPLASH_DURATION = 3000;

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
Handler handler = new Handler();
               handler.postDelayed(new Runnable()
        {
            @Override
            public void run()
            {
                finish();
                if (!mIsBackButtonPressed)
                {
                    Intent intent = new Intent(Splash.this,second.class);
                    startActivity(intent);
                }
            }
        }, SPLASH_DURATION);

    }

public void onBackPressed()
{
        mIsBackButtonPressed = true;
        super.onBackPressed();
    }



2. Create a Another class called second.class

   package com.example.game;

   public class second extends Activity
  {
  public void onCreate(Bunble b)
  {
     super.onCreate(b);
    setContentView(R.layout.second);

}
}

3.create a xml called splash.xml


splash.xml:

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:text="Welcome to Android Tutorials" />

</RelativeLayout>


4.Another layout called second.xml


second.xml:

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:text="Hello World" />

</RelativeLayout>


5.Run the Application and  the output is shown below





       

   


No comments :

Post a Comment