jueves, 8 de septiembre de 2016

Crear un Splash de Android en 5 pasos

Crear un SPLASH en Android Studio





1-.Crear un proyecto con un template en blanco.

2-.Agregar un archivo en los layout con el nombre de "splash.xml" y agregamos lo siguiente:



LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@drawable/splash_image"
 android:orientation="vertical"

/LinearLayout


3-.Crear un Clase en el paquete con lo siguiente:

package com.coderefer.androidsplashscreenexample;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

/**
 * Created by vamsikrishna on 12-Feb-15.
 */
public class SplashScreen extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        Thread timerThread = new Thread(){
            public void run(){
                try{
                    sleep(3000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent intent = new Intent(SplashScreen.this,MainActivity.class);
                    startActivity(intent);
                }
            }
        };
        timerThread.start();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }

}


4-.En el archivo de AndroidManifest.xml agregar lo siguiente:



 application
 android:allowBackup="true"
 android:icon="@mipmap/ic_launcher"
 android:label="@string/app_name"
 android:theme="@style/AppTheme" 

 activity
 android:name=".SplashScreen"
 android:label="@string/app_name" 
 intent-filter
 action android:name="android.intent.action.MAIN" /

 category android:name="android.intent.category.LAUNCHER" /
 /intent-filter
 /activity

 activity
 android:name=".MainActivity"
 android:label="@string/app_name" 
 intent-filter>
 action android:name="com.coderefer.androidsplashscreenexample.MAINACTIVITY" /

 category android:name="android.intent.category.DEFAULT" /
 /intent-filter
 /activity
 /application




5-.Por ultimo compilamos y ejecutamos el apps.

Con estos cinco pasos ya tenemos nuestr primer Splash.

No hay comentarios.:

Publicar un comentario