Pada kali ini kita akan membuat tampilan splash screen atau tampilan awal pada saat membuka sebuah aplikasi android.
(simpan file xml dengan nama splash.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/padi" // backgroun ganti aja
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="150dip"
android:text="WELCOME"
android:textColor="#ffffff"
android:textSize="50dip"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading..."
android:layout_gravity="center_horizontal"
android:textColor="#ffffff"
android:textSize="20dp" />
<ProgressBar
android:layout_gravity="center_horizontal"
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
----------------------------------------------------------------------------------------------------------------------------
- Membuat java untuk pemanggilan splash.xml nya
(simpan dengan nama SplashScreen.java)
package com.heru.smartfarming;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
public class SplashScreen extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash);
/*menjalankan splash screen dan menu menggunakan delayed thread*/
new Handler().postDelayed(new Thread() {
@Override
public void run() {
Intent mainMenu= new Intent(SplashScreen.this,MainActivity.class);
SplashScreen.this.startActivity(mainMenu);
SplashScreen.this.finish();
overridePendingTransition(R.layout.in,R.layout.out);
}
}, 3000);
}
}
--------------------------------------------------------------------------------------------------------------------------
- Membuat 2 buah xml untuk pengaturan lama waktu
- simpan dengan nama in.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="1000"
android:fromAlpha="0.0"
android:toAlpha="1.0"/>
2.
simpan dengan nama out.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="1000"
android:fromAlpha="1.0"
android:toAlpha="0.0"/>
--------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.heru.smartfarming"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ico"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.heru.smartfarming.MainActivity" // jangan lupa di ubah
android:label="@string/app_name" >
</activity>
<activity
android:name="com.heru.smartfarming.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>
</application>
</manifest>
--------------------------------------------------------------------------------------------------------------------------
selamat mencoba :)
good luck