Saturday, July 13, 2013

Android Splash Screen with Back ground and logo Tutorial

Simple Splash Screen with back Ground and Icon 
 This splash screen displayed using thread by allowing particular interval of time sleep 
  I am writing code for displaying splash screen with background image and logo 

  Note :  put your background image and logo in res-draw-able folder 

1) Create Class Image which extends View
    This class  create the canvas and initiate background image or color and icon in the canvas

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;

import android.view.View;
public class Image extends View {
Bitmap bitmapOrg;

int b, c;

public Image(Context context) {

super(context);

bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.logo);

}

@Override
protected void onDraw(Canvas canvas) {

super.onDraw(canvas);
toHelpDrawing(canvas);
}

private void toHelpDrawing(Canvas canvas) {
b = getWidth();
c = getHeight();
setBackgroundResource(R.drawable.backgrounds) ;
       // setBackgroundColor(Color.GRAY);
canvas.drawBitmap(bitmapOrg, b / 2 - bitmapOrg.getWidth() / 2, c / 2
- bitmapOrg.getHeight() / 2, null);

}
}

2)  Create class Splash which will call Image class and using thread allow display the screen particular interval of time then next activity will appear

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;



public class Splash extends Activity {
//private DataBaseTableCreater dbtc;
//DBAdapter dba=new DBAdapter(this);
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      

        setContentView(new Image(this));
       // dbtc=new DataBaseTableCreater(this);
       // dbtc.createTables();
        //dbtc=null;
        //Constants c = new Constants();
        Thread splashTimer =new Thread()
        {
        public void run()
        {
        try{
        sleep(2000);
                        startActivity(new Intent(Splash.this,LoginDummy.class));
                     } 
        catch(Exception e)
        {
        Log.e("splash",e.toString());
        }
        finally
        {
        finish();
        }
        }
        };splashTimer.start();
    }
}
  
It is the standard splash screen without using xml layout in my next tutorial i will write the splash screen using xml layout 

if you have any doubt comment it 

No comments:

Post a Comment