Splashscreen codes




 
The code below is for splash.java

package com.example.splashscreen;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.animation.Animation;
import android.view.animation.LayoutAnimationController;
public class SplashAnimation extends Activity {
    private static final int TIME = 4 * 1000;// 4 seconds
    LayoutAnimationController controller;
    Animation fade1;
    Animation fade2;
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_anim);
        new Handler().postDelayed(new Runnable() {
           // this is athread
            @Override
            public void run() {
                Intent intent = new Intent(SplashAnimation.this,
                        MainActivity.class);
                startActivity(intent);

                SplashAnimation.this.finish();

                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }
        }, TIME);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
            }
        }, TIME);
    }
    @Override
    public void onBackPressed() {
        this.finish();
        super.onBackPressed();
    }
    @Override
    public void onDestroy(){
        super.onDestroy();
    
    }
}

The below are the codes for fade in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:fillAfter="true">
     <alpha android:fromAlpha="0.0"
            android:toAlpha="1.0"
            android:duration="4000"/> //Milliseconds
</set>
The below are the codes for the fade out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:fillAfter="true">
     <alpha android:fromAlpha="1.0"
            android:toAlpha="0.0"
            android:duration="4000"/> //Miliseconds
</set
The below code is for splash.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#006600"
    android:orientation="vertical" >

</LinearLayout>
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment