Membuat splash screen android


kali inikita mencoba membuat  splash screen pada android  😀

splash

ok cekidot gan
bahannya

1 file layout yang untuk splash screennya beserta  file java (splash.java dan splash.xml )

2 file utama (MainActivity.java dan MainActivity.xml)

file splash.java


package com.example.splash_screen;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);

Thread timer = new Thread() {
public void run() {
try {
//berapalama splashscreen akan ditampilkan dalam milisecond
sleep(3000);
} catch (InterruptedException e) {
// TODO: handle exception
e.printStackTrace();
} finally {
//activity yang akan dijalankan setelah splashscreen selesai
Intent i = new Intent(splash.this,MainActivity.class);
startActivity(i);
}
}
};
timer.start();
}
public void onBackPressed() {
}

}



file 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="fill_parent"

android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:text="SPLASH SCREEN"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30sp"
android:typeface="serif" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Keep Your Account Data Safety"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:layout_marginTop="10dp"
android:text="99,99 % SECURE"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />



<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="LOADING . . ."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />

</LinearLayout>

file MainActivity.java


package com.example.splash_screen;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onBackPressed() {
}
@Override
protected void onRestart() {
super.onRestart();  // ini dipasang jika aplikasi di hide akan kembali ke splash lagi hilangkan saja bila tidak diperlukan
Intent myIntent = new Intent(this, splash.class);
startActivityForResult(myIntent, 0);
}

}

file MainActivity.xml


<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"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />

</RelativeLayout>



download kodenya

semoga berguna:)

Iklan

tinggalkan pesan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: