Cara Membuat Slide Menu di Android Studio
Pertama bikin project dulu, misal namanya Slide
siapkan gambar buat icon menunya, gambarnya terserah situ aja, dan copy gambar tersebut ke folder res->drawable-hdpi
lalu buat lah class Baru yang dikasih nama SlideAdapter.java isikan code seperti ini
setelah itu edit activity_main.xml seperti ini
untuk MainActivity.java edit seperti ini
seteleah itu buatlah 3 Aciivity Baru yanga di Kasih nama Index,Help,dan About, biarkan kondisi nya sesuai sesuai default,.
Kalo Berhasil Pasti Hasilnya gini
Download Projectnya disini
siapkan gambar buat icon menunya, gambarnya terserah situ aja, dan copy gambar tersebut ke folder res->drawable-hdpi
lalu buat lah class Baru yang dikasih nama SlideAdapter.java isikan code seperti 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
46
47
48
49
50
| package com.slide; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; public class SlideAdapter extends BaseAdapter { private Context context; // array of integers for images IDs private Integer[] gambarMenu = { R.drawable.index, R.drawable.about, R.drawable.help, }; public SlideAdapter(Context c) { context = c; } @Override public int getCount() { return gambarMenu.length; } @Override public Object getItem( int i) { // TODO Auto-generated method stub return i; } @Override public long getItemId( int i) { // TODO Auto-generated method stub return 0 ; } @Override public View getView( int i, View view, ViewGroup viewGroup) { ImageView imageView = new ImageView(context); imageView.setImageResource(gambarMenu[i]); imageView.setLayoutParams( new Gallery.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); return imageView; } } |
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
| <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:id= "@+id/LinearLayout1" android:layout_width= "match_parent" android:layout_height= "match_parent" android:background= "@drawable/back" android:orientation= "vertical" 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= ".SlidingMenu" > <Gallery android:id= "@+id/gallery" android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:layout_marginBottom= "50dip" android:paddingTop= "80dp" /> <LinearLayout android:id= "@+id/image_count" android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:background= "#00000000" android:gravity= "center" android:orientation= "horizontal" > </LinearLayout> </LinearLayout> |
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
| package com.slide; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.graphics.Color; import android.graphics.Typeface; import android.view.Menu; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Gallery; import android.widget.LinearLayout; import android.widget.TextView; public class MainActivity extends Activity { private static TextView DotsText[]; private int DotsCount; private LinearLayout DotsLayout; public static int l; public static int idxMenu; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Gallery gallery = (Gallery) findViewById(R.id.gallery); gallery.setAdapter( new SlideAdapter( this )); DotsLayout = (LinearLayout) findViewById(R.id.image_count); DotsCount = gallery.getAdapter().getCount(); DotsText = new TextView[DotsCount]; for ( int i = 0 ; i < DotsCount; i++) { DotsText[i] = new TextView( this ); DotsText[i].setText( "." ); DotsText[i].setTextSize( 45 ); DotsText[i].setTypeface( null , Typeface.BOLD); DotsText[i].setTextColor(android.graphics.Color.GRAY); DotsLayout.addView(DotsText[i]); gallery.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { switch (position) { case 0 : Intent intent_index = new Intent(MainActivity. this , Index. class ); startActivity(intent_index); break ; case 1 : Intent intent_help = new Intent(MainActivity. this , Help. class ); startActivity(intent_help); break ; case 2 : Intent intent_about = new Intent(MainActivity. this , About. class ); startActivity(intent_about); break ; } } }); gallery.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @SuppressWarnings( "rawtypes" ) @Override public void onItemSelected(AdapterView adapterView, View view, int position, long l) { // status.setText(menu_name[position]); for ( int i = 0 ; i < DotsCount; i++) { MainActivity.DotsText[i].setTextColor(Color.GRAY); } MainActivity.DotsText[position].setTextColor(Color.WHITE); } @SuppressWarnings( "rawtypes" ) @Override public void onNothingSelected(AdapterView adapterView) { } }); } } } |
Kalo Berhasil Pasti Hasilnya gini
Download Projectnya disini
0 comments:
Post a Comment