dimanche 8 février 2015

ANDROID STUDIO; splash introduction

Splash  Introduction



Comment faire afficher un écran temporaire d'accueil sur une application ?




Modifier le manifest:

dans le manifest cohabitent deux "activity"
            android:name="com.tontonzition.monintro.Splash"
            android:name="com.tontonzition.monintro.MainActivity"

---------------------------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"
    package="com.tontonzition.monintro" >

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.tontonzition.monintro.Splash"
            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="com.tontonzition.monintro.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.STARTINGPOINT" />

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

</manifest>
 _________________________________________________________

dans le Layout on crée un nouveau xml qui affiche le logo, lors du demarrage de l'application
Il faudra aussi placer l'image logo.png dans le répertoire
......MonIntro\app\src\main\res\drawable-hdpi

_____________________________________________________________
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView"
        android:src="@drawable/logo"
        android:scaleType="center" />
</LinearLayout>

_____________________________________________________________

On crée aussi une nouvelle classe: Splash.java
cette classe contient la durée de temporisation  puis l'appel à la deuxième entrée d'activity du manifest.
try{sleep(5000);
Intent openStartingPoint = new Intent("android.intent.action.STARTINGPOINT");


______________________________________________________________

package com.tontonzition.monintro;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.tontonzition.monintro.R;
/**
 * Created by Louis on 08/02/2015.
 */
public class Splash  extends Activity {


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);
            Thread timer = new Thread(){
                public void run(){
                    try{sleep(5000);


                    } catch (InterruptedException e){
                        e.printStackTrace();
                    }finally{
                        Intent openStartingPoint = new Intent("android.intent.action.STARTINGPOINT");
                        startActivity(openStartingPoint);
                    }
                }
            };
            timer.start();

        }
        @Override
        protected void onPause() {
            super.onPause();
            finish();
        }



}
_________________________________________________________________


Aucun commentaire:

Enregistrer un commentaire