Saturday, April 30, 2011

Splash Screen In Android ....

.XML File

<?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"
  android:background="@drawable/splashbackground"
  android:layout_gravity="center"
  android:gravity="center"
  android:orientation="vertical">
 
  <ImageView
  android:src="@drawable/logo"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
     android:id="@+id/logo"/>
    
     <TextView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/shipbell"
     style="@style/textview"
android:layout_marginTop="8dip"
     />
</LinearLayout>


.JAVA File


package com.bell.shipclock;

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

public class SplashScreen extends Activity {
    protected boolean _active = true;
    protected int _splashTime = 5000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.splashscreen);
       
        Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    Intent intent =new Intent(SplashScreen.this, Home.class);
                    startActivity(intent);
                    stop();
                }
            }
        };
        splashTread.start();
       
       

    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            _active = false;
        }
        return true;
    }
   
   

}

No comments:

Post a Comment