Membuat Splash Screen Sederhana Android

CARA MEMBUAT SPLASH SCREEN SEDERHANA AIDE ANDROID STUDIO

Apa itu splash screen ?


Splash screen merupakan tampilan yang muncul saat pertama kali kita membuka sebuah aplikasi.

Splash screen biasanya menampilkan logo, nama, dan lainnya yang berhubungan dengan aplikasi.

Bagaimana cara membuat splash screen?


Buatlah project baru atau edit aplikasi anda.
Buat file splashscreen.xml Tambahkan imageView pada layout anda. jangan lupa menambahkan gambar logo anda pada folder drawable.

splashscreen.xml


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

 <ImageView
  android:id="@+id/splashlogoImageView"
  android:src="@drawable/splashscreen"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:gravity="center"
  android:layout_gravity="center"
  android:layout_centerVertical="true"
  android:layout_centerHorizontal="true"/>

</RelativeLayout>


       


Langkah selanjutnya buat folder anim di dalam folder res, Lalu buat file animfadein.xml dan animfadeout.xml didalam folder anim

animfadein.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/accelerate_interpolator" >

 <alpha
  android:fromAlpha="0"
  android:toAlpha="1" 
  android:duration="2000" >
 </alpha>


</set>

       


animfadeout.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
 android:interpolator="@android:anim/accelerate_interpolator" >

 <alpha
  android:fromAlpha="1"
  android:toAlpha="0" 
  android:duration="2000" >
 </alpha>


</set>

       


Selanjutnya buat file splashscreen.java, buatlah splashscreen dengan efek transisi

splashscreen.java

package com.sevenkm.splashscreen;
import android.app.*;
import android.widget.ImageView;
import android.view.Window;
import android.view.WindowManager;
import android.os.Handler;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation;

public class splashscreen extends Activity
{
 // # Waktu tunda untuk splash logo
 private int SPLASH_DISPLAY_LENGTH = 2500;

 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  // # Buat tampilan layar penuh dan tanpa judul aplikasi
  requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
  // # Buat tampilan layar splash
  setContentView(R.layout.splashscreen);

  getSplashLogo();

 }


 public void getSplashLogo(){
  // # temukan id Gambar splash logo
  ImageView logosplash = (ImageView)findViewById(R.id.splashlogoImageView);
  // buat animasi keluarnya splash screen
  Animation fadeefk = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animfadein);
  logosplash.startAnimation(fadeefk);
  // # Buat waktu tunda pindah ke halaman utama
  final Handler HANDLER_PINDAH = new Handler();
  // # Jalankan waktu tunda
  HANDLER_PINDAH.postDelayed(new Runnable(){
    @Override 
    public void run()
    {

     // # pindah ke halaman utama setelah waktu tunda berakhir
     Intent I_UTAMA = new Intent(getApplicationContext(), MainActivity.class);
     // # pindahkan ke menu utama
     startActivity(I_UTAMA);
     // buat transisi pindah halaman
     overridePendingTransition(R.anim.animfadein, R.anim.animfadeout);
     // # Tutup halaman ini dan tidak di tampilkan lagi
     finish();

    }
   }, SPLASH_DISPLAY_LENGTH);
 }

}
       


Langkah terakhir edit file AndroidManifest.xml, Tambahkan activity <activity
android:name=".splashscreen"
android:label="@string/app_name"
android:screenOrientation="portrait">
kedalam file AndroidManifest.xml. Ubah <intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
pada activity MainActivity Menjadi <intent-filter>
<action android:name="android.intent.action.DEFAULT" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
. Lihat kode di bawah ini.

AndroidManifest.xml


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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
  <activity
            android:name=".splashscreen"
            android:label="@string/app_name" 
            android:screenOrientation="portrait">
            <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="android.intent.action.DEFAULT" />

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

</manifest>
        
       


Download example project :






Komentar

Posting Komentar