Skip to content Skip to sidebar Skip to footer

Add Navigation Drawer With Tabs In Fragment

Acualy i created a navigation Drawer activity and this activiy works perfectly but i want to add the first item of Navigaion Drawer with tab layout and the remaining item with the

Solution 1:

To add the Tablayout with NavigationDrawer :

1.create a new File “TabFragment.java” to inflate & code TabLayout and viewPager elements.

2.For viewPager to display content it requires a Adapter . use a FragmentPagerAdapter which is used to inflate tab specific fragments.

3.The FragmentPagerAdapter overrides three main methods :

a) getCount() : It returns the total number of tabs to be bind with the view pager.

b) getItem(int position) : It returns the tab-specific fragment wrt to its position.

c) getPageTitle(int position)` : It returns name of the title according to the position

4.At the end , attach your ViewPager with the TabLayout with the setupWithViewPager(viewPager) method of the TabLayout .

Here is a detail implementation: https://androidbelieve.com/navigation-drawer-with-swipe-tabs-using-design-support-library/

Hope it helps.

As u are using toolbar you can use:

@OverridepublicbooleanonNavigationItemSelected(MenuItem menuItem) {
    //Checking if the item is in checked state or not, if not make it in checked stateif (menuItem.isChecked()) menuItem.setChecked(false);
    else menuItem.setChecked(true);

    //Closing drawer on item click
    drawerLayout.closeDrawers();

    //Check to see which item was being clicked and perform appropriate actionswitch (menuItem.getItemId()) {

    case R.id.first:
            toolbar.setTitle("First Item");
            returntrue;

    case R.id.second:
            toolbar.setTitle("Second Item");
            returntrue;
     }
}

to set title..during click on fragments

Post a Comment for "Add Navigation Drawer With Tabs In Fragment"