Home / Libraries / Android Sliding Menu Library Tutorial – Library #3

Android Sliding Menu Library Tutorial – Library #3

This is library #3 in this series 100 Library in Android , in the previous article we had Android Universal Image Loader Tutorial. In this tutorial we are having the Android Sliding Menu Library which is an Open Source Android library that allows developers to easily create applications with sliding menus like those made popular in the Google+, YouTube, and Facebook apps.

Our App: 

Our app will use Android Sliding Menu Library to make a sliding menu with a background image and user avatar and the output would be like this image below.

Android Sliding Menu Library

Android Sliding Menu Library Tutorial

Technical Overview: 

  1. The application will have single activity and a fragment for the menu.
  2. The menu layout has recyclerView to hold the menu items and a user avatar image.
  3. The menu fragment will inflate its layout and set adapter for the recyclerView and attach onClick listener for the recyclerView items and for the user avatar.
  4. Also we need Adapter class for the recyclerView, and a class to hold menu items with attributes (Icon, Title).

So, the project file structure would be like this:

Android Sliding Menu Library Tutorial

So lets get into code and start Android Sliding Menu Library Tutorial step by step:

1. Creating Android Project, In Android Studio, create a new project by navigating to File ⇒ New Project and fill all the required details. When it prompts to select a default activity, select Empty Activity and proceed. you can download images and icons used in this app from this linkjust extract this .zip file under res folder

2.   How to install Sliding Menu Library in Android Studio:

– Download the library as zip from here.

– https://github.com/jfeinstein10/SlidingMenu/tree/master/library is the main lib, extract the zip file and rename library folder to SlidingMenu.

– Put the project then to your project root directory, so the project structure will look like this image:

Android Sliding Menu Library Tutorial

– Open build.gradle in library folder (marked with purple) and modify this part to be like this:

– Now Lets edit our app files in include the library:

Modify settings.gradle file (marked with green) and add this code:

and In your app build.gradle (marked with green) add this code:

Sync the Gradle files, you may find an error “SDK version or Build-Tools” is missing, download and install it and run again, now the library should be installed and ready to use.

3. Lets create a new fragment which holds our menu and manage its functions like click listeners and so on, under your package name, create a blank fragment , call it SlidingMenuFragment and click finish.

in the fragment layout file fragment_sliding_menu put this code, it has an imageView and the recyclerView which will hold our menu list.

4. Now create a class for single item in menu which has just title and icon, under your package name, make a new class and name it ItemMenu, and out this code into it:

also we need to create a layout for single menu item to put our icon and title into place, so under res folder make a new layout file, call it menu_row and put this code into it, it will have just an ImageView and TextView

4. We need an adapter class to adapt menu items data with the recyclerView into the fragment layout, so under your package create a new class call it MenuRecyclerViewAdapter and put this code into it.

Note: We had a simple tutorial showing how to make Recyclerview with custom adapter, you can have a quick look on it and continue this tutorial.

5. Time now to put all together and use our recyclerView adapter and menu items in our fragment, open SlidingMenuFragment.java and add this code.

We made objects from the recyclerView, ImageView used in fragment layout and attached a click listener to them, this video explains how the recyclerView click listener works, i recommend you guys have a look on it.

6. Finally in our MainActivity.java file we need to put this code, we created an object from the Sliding Menu class and configure its settings like fade, shadow, position (LEFT or RIGHT) and then attach it to our activity.

Run the project and test it. You should able see the Android sliding menu library tutorial output works like the first image in the tutorial, try making the menu slide from right and try different shadow and fade values.

I hope you like this tutorial guys and we are waiting your feedback and requests.

Article Title
Android Sliding Menu Library Tutorial - Library #3
Android Sliding Menu Library Tutorial, the menu layout has recyclerView to hold the menu items and adapter for the recyclerView and attach onClick listeners
Android Gifts

About #AndroidGifts


Check Also

ZXing (Zebra Crossing) Android Library Tutorial – Library #4

This is library #4 in this series 100 Library in Android , in the previous article we had …

Leave a Reply