Double-side Nav Drawer
I have used Android Studio 1.5.1 Build 141.2456560. So here we go.
1) Navigation Drawer Activity
When creating a New Project, choose Navigation Drawer Activity. This makes things easy.
When creating a New Project, choose Navigation Drawer Activity. This makes things easy.
If this option is not available, you can the simply choose Blank Activity and later make the project structure similar to Navigation Drawer Activity. See the layout files here.
If you run the app at this point, you will see the Left Nav Drawer.
2) Navigation Views
As you can see I have added 2 Navigation Views inside Drawer Layout...one for left-side and other for right-side. For the Right-side, add android:layout_gravity="end"
Other thing you will notice is app:menu.The easiest way to add menu items within the NavDrawer is through XML.
3) Drawer Menu Items
Inside menu folder, add two XMLs --- activity_main_drawer.xml (for left-drawer) and activity_right_drawer.xml (for right-drawer).
To the main.xml file which shows Settings in an overflow menu on the top-right, make these changes. You can add any icon of your choice.
5) Navigation Item Selected Listeners
The only important line to notice is drawer.closeDrawer(GravityCompat.END); for the Right NavDrawer. Otherwise the code is simple,well-commented and easy to implement.
The complete code is here
Comments
Post a Comment