pasti udah tau kan Splash Screen , semacam kaya Loading gitu lah :)
- Buat Project File ⇒ New ⇒ SplashScreen dan Beri nama Activity splash_activity.
- Copy'kan gambar di drawable-mdpi yang mau jadi background saat Splash Screen
- Buka splash_activity.xml dan ikuti Code di bawah ini :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/zx"
tools:context=".Splash" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="44dp"
android:text="Mohon tunggu Sebentar . . . " />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="102dp"
android:layout_marginLeft="17dp" />
</RelativeLayout>
- Buka Splash.java yang berada pada src->com.example.splashscreen dan ikuti code di bawah ini :
package com.example.splashscreen;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
public class Splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);
final int welcomeScreenDisplay = 3000;
Thread welcomeThread = new Thread() {
int wait = 0;
@Override
public void run() {
try {
super.run();
while (wait < welcomeScreenDisplay) {
sleep(100);
wait += 100;
}
} catch (Exception e) {
System.out.println("EXc=" + e);
} finally {
startActivity(new Intent(Splash.this,Tampil.class));
finish();
}
}
};
welcomeThread.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
- selanjut'nya kita buat lagi XML dengan nama tampilan.xml dan isi code seperti ini
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cee"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Sukses"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
- selanjut'nya kita buat Class baru dengan nama Tampil.java dan beri code seperti di bawah ini :
package com.example.splashscreen;
import android.app.Activity;
import android.os.Bundle;
public class Tampil extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tampilan);
}
}
Nah selesai deh waktu'nya kita RUN !
dan taraa . . . . . . . . . .
Bila ga mau repot tinggal Download File'nya nih => Download
Sekian dari saya , bila masih bingung , bisa di tanyakan melali media sosial , atau bisa komentar di blog ini :)
Post a Comment