Facebook Style Slide Menu In Android
Posted By : Arpit Sharma | 25-Apr-2013
Today I will blog on Facebook style slide menu in android, you have to follow the given step in order to implement fb style menu.
- Create a new android project in eclipse(Minimum Required Android SKD 2.2 ).
- Download slider.jar file from here.
- Place slider.jar in lib folder in project
Now our basic project structure is ready and its time to focus on layouts, replace main.xml code from given one.
<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" > <Button android:id="@+id/left_buton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="Left Menu" /> <Button android:id="@+id/right_buton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="Right Menu" /> </RelativeLayout>
- Create two Android XML Files one for left menu and other for right menu say "left_menu.xml" and "right_menu.xml".
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="260dp" android:layout_height="wrap_content" android:gravity="center" android:text="Left Menu" android:textColor="#ffffff" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#000000" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="260dp" android:layout_height="wrap_content" android:gravity="center" android:text="Right Menu" android:textColor="#ffffff" /> </LinearLayout>
- There are some pre defined funstions in "slider.jar" which help us to create fb style slide menu.
* setLeftBehindContentView(left_layout) is used to set left menu.
* setRightBehindContentView(right_layout) is used to set right menu.
* toggleLeftDrawer() is used to show the left menu.
* toggleRightDrawer() is used to show the right menu.
- Now, open "MainActivity.java" and place the given code in it.
package com.example.slide_menu; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import com.navdrawer.SimpleSideDrawer; public class MainActivity extends Activity { SimpleSideDrawer slide_me; Button left_button, right_button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); slide_me = new SimpleSideDrawer(this); slide_me.setLeftBehindContentView(R.layout.left_menu); slide_me.setRightBehindContentView(R.layout.right_menu); left_button = (Button) findViewById(R.id.left_buton); right_button = (Button) findViewById(R.id.right_buton); left_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub slide_me.toggleLeftDrawer(); } }); right_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub slide_me.toggleRightDrawer(); } }); } }
Arpit Sharma
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Arpit Sharma
Arpit has been developing Android and iPhone applications for a while now and is expert in mobile application development . He excels in developing mobile applications with location based intelligence. Arpit loves Modelling as a hobby.