Tab View Inside Navigation Drawer for android

To create a project that displays Tab View inside navigation drawer selection. By simple step by step process. It’s simple to combine tab view inside navigation drawer. First start by creating a “Navigation Drawer Activity” in android studio (assuming you are aware of those things). Second part is to create a fragments to handle the navigation drawer activities.

This flow chart may help you to better understand what we want to achieve.

Tab View inside Navigation Drawer image logicchip 1

FragmentA contains the Tablayout (Tab View) and view pager, the navigation drawer pass id to FragmentA it displays tabs and content to be displayed in the viewpager according to the navigation drawer and tab selected. In this case the id passed is the name of navigation drawer menu.

Tab View inside Navigation Drawer image logicchip4

This project contains. => Navigation Drawer Activity. => Fragment containing Tab View. => Fragment for viewpager. => Fragment for running first and menu without tabs. => Class file for keeping constant values. => It’s a Fragment Page Adapter to handle FragmentB from FragmentA. => for handling communication between Fragment and parent activity.

Below is a simple step by step explanation.


This class contain only key values for passing data to fragments.


A simple interface for communicating between fragments and parent activity.




This fragment is only for displaying message of those menu that don’t have any tabs. The arguments are the name of navigation menu name (id).





FragmentB is for displaying the contents of the tab selected. The arguments are the name of the selected tabs (id).





This class file is an adapter for handling instance of tabs selected, which displays contents of FragmentB according to the tab selected. It extents FragmentPagerAdapter class.




This fragment contains tablayout and viewpager. FragmentB is displayed inside viewpager. FragmentA is placed inside the parent activity, so when clicking a menu item it displays Parent Activity and inside it FragmentA with Tabs and Viewpager also FragmentB inside Viewpager.
This figure shows how it’s implemented.

Tab View Inside Navigation Drawer logicchip 2





The is the launcher activity (parent activity) it implements navigation item selected listener and OnFragmentInteractionListener (our 2nd step mentioned above). Coding take place in the “onNavigationItemSelected (MenuItem item)” method, handling the menu items clicks. Another method name “homeFragment ()” is also created to display when starting up otherwise we get a blank screen when starting. Back pressed method “onBackPressed ()” is slightly modified to handle back click for selected drawer menu item. All the other things we need are already included in the template “Navigation Drawer Activity in Android Studio”.
Because it’s Navigation Drawer it contains more than one xml file.


Download full source code for free

10 thoughts on “Tab View Inside Navigation Drawer for android

Leave a Reply

%d bloggers like this: