Tuesday, 9 June 2015

Membuat Spash Screen

Tutorial ini sangat simple ,
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 : 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<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 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
    }
 
}
1
  
  • selanjut'nya kita buat lagi XML dengan nama tampilan.xml dan isi code seperti ini 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?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>
1
 selanjut'nya kita buat Class baru dengan nama <strong>Tampil.java </strong>dan beri code seperti di bawah ini :
1
2
3
4
5
6
7
8
9
10
11
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);
    }
}
  • dan selesai , coba di run
  • maaf bila tutorial ini berantakan , soal'nya baru pertama kali buat tutorial di sini ^^"
  • bila masi ada error coba di tanyain di sini , thx 

No comments:

Post a Comment