Thursday, October 2, 2014

Android Sliding Menu using Navigation Drawer/ Hamburger

Download the Demo Project From Following link and import it in your eclipse ide.

Download

1. Find the String variables for List View items and icon names in strings.xml.(change as per your needs.)
2. Android introduced a newer UI element called DrawerLayout for Navigation Drawer. Open your layout file (activity_main.xml) for main activity and type the following code.
Here FrameLayout is used to replace the main content using Fragments and it should be always the first child of the layout for z-index purpose.
3.list_item_bg_normal.xml  and list_item_bg_pressed.xml represents list item state when normal and pressed.
4. Created another xml file to combine both the drawable states under res ⇒ drawable named list_selector.xml
5.counter_bg.xml  used  for rounde corner background for the counter value.
6. As listview has the custom layout, we need another layout file which defines the each list row. So create a layout file under res ⇒ layout named drawer_list_item.xml. This is a relative layout which places the icon, title and counter relative to one another.
7. In NavDrawerItem.java, isCounterVisible defines the visibility of the counter value.
8. in MainActivity.java, invalidateOptionMenu() is called in onDrawerOpened() and onDrawerClosed() to hide and show the action bar icons on navigation drawer opened and closed.

No comments:

Post a Comment