Langsung saja ke kodingannya ya, supaya saya tidak panjang lebar lagi ngomongnya. hehe
Pertama kita buat splash.java
import jie.belajar.android.BuserActivity;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.MotionEvent;
public class Splash extends Activity {
protected boolean _active = true;
protected int _splashTime = 2000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.splash);
// thread for displaying the SplashScreen
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
finish();
Intent newIntent=new Intent(Splash.this,BuserActivity.class);
startActivityForResult(newIntent,0);
}
}
};
splashTread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
_active = false;
}
return true;
}
}
Selanjutnya kita buat splash.xml
Untuk splash.xml saya tambahin progressBar, supaya tampilannya lebih menarik :D
<?xml version="1.0" encoding="utf-8"?>NB : Untuk yang berwarna Merah berarti saya membuat splash screen dari gambar dari folder drawable dengan nama splash.png.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|center_horizontal"
android:background="@drawable/splash">
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Terakhir untuk AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jie.belajar.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".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=".BuserActivity"
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>
Oke sudah selesai, segitu saja... hehe
sumber : http://priawadi.blogspot.com/2012/06/membuat-splash-screen-android.html
This comment has been removed by the author.
ReplyDeletebang, kan uda buat file" di atas.. jadi total ada 4 file + gambar..
ReplyDeletegambarnya dtaruh drawable.. trus 3 file lainnya dtaruh mana??
This comment has been removed by a blog administrator.
ReplyDelete