Assalamualaiqum ☺
Siang ini kita akan membahas tentang cara membuat leaflet sederhana berbasis android. Disini kita hanya menggunakan view – view saja atau hanya berpindah ke layout lainnya.
Ok langsung saja simak langkah – langkah membuatnya:
- Buat project baru dengan nama Leaflet.
- Buat file xml dan java
- Source code file activity_awal.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"
android:background="@drawable/awal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".AwalActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="191dp"
android:background="@drawable/menu" />
</RelativeLayout>
Tampilannya menjadi:
- Isikan source code pada file activity_menu.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"
android:background="@drawable/menu1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MenuActivity" >
<Button
android:id="@+id/dosen"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/dosen"
android:layout_marginLeft="30dp"
android:layout_marginTop="150dp"
/>
<Button
android:id="@+id/ahli"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/ahli"
android:layout_marginLeft="190dp"
android:layout_marginTop="150dp"
/>
<Button
android:id="@+id/prestasi"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/prestasi"
android:layout_marginLeft="30dp"
android:layout_marginTop="290dp"
/>
<Button
android:id="@+id/lab"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/lab"
android:layout_marginLeft="190dp"
android:layout_marginTop="290dp"
/>
</RelativeLayout>
Hasilnya akan menjadi seperti berikut:
- Source code file activity_dosen.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"
android:background="@drawable/dosen1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".DosenActivity" >
</RelativeLayout>
Hasilnya:
- Source code file activity_ahli.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"
android:background="@drawable/ahli1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".AhliActivity" >
</RelativeLayout>
Hasilnya:
- Source code file activity_lab.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"
android:background="@drawable/lab1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".LabActivity" >
</RelativeLayout>
Hasilnya:
- File activity_prestasi.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"
android:background="@drawable/prestasi1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".PrestasiActivity" >
</RelativeLayout>
Hasilnya:
- Selanjutnya source code file AwalActivity.java
package com.example.leafletit;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class AwalActivity extends Activity implements OnClickListener {
Button Menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_awal);
Button Menu = (Button) findViewById(R.id.button1);
Menu.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.awal, menu);
return true;
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent Menu = new Intent (AwalActivity. this, MenuActivity.class);
startActivity(Menu);
}
}
- File MenuActivity.java
package com.example.leafletit;
import com.example.leafletit.DosenActivity;
import com.example.leafletit.LabActivity;
import com.example.leafletit.PrestasiActivity;
import com.example.leafletit.AhliActivity;
import com.example.leafletit.MenuActivity;
import com.example.leafletit.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MenuActivity extends Activity implements OnClickListener {
Button dosen;
Button ahli;
Button prestasi;
Button lab;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
Button dosen = (Button)findViewById(R.id.dosen);
Button ahli = (Button)findViewById(R.id.ahli);
Button prestasi = (Button)findViewById(R.id.prestasi);
Button lab = (Button)findViewById(R.id.lab);
dosen.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent masuk = new Intent(MenuActivity. this, DosenActivity.class);
startActivity(masuk);
}
});
ahli.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent masuk = new Intent (MenuActivity. this, AhliActivity.class);
startActivity(masuk);
}
});
prestasi.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent masuk = new Intent (MenuActivity. this, PrestasiActivity.class);
startActivity(masuk);
}
});
lab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent masuk = new Intent(MenuActivity. this, LabActivity.class);
startActivity(masuk);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
- File AhliActivity.java
package com.example.leafletit;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class AhliActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ahli);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.ahli, menu);
return true;
}
}
- File DosenActivity.java
package com.example.leafletit;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class DosenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dosen);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dosen, menu);
return true;
}
}
- File LabActivity.java
package com.example.leafletit;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class LabActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lab);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.lab, menu);
return true;
}
}
- File PrestasiActivity.java
package com.example.leafletit;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class PrestasiActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prestasi);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.prestasi, menu);
return true;
}
}
- Terakhir jalankan program di emulator atau smartphone anda.
Semoga Bermanfaat ☺
0 komentar:
Posting Komentar