25

I have a sliding drawer menu in an activity, which has an actionbar with some tabs on it.

I'd like to get the sliding drawer to slide over the tabs , not below them.

This is what it looks like right now...

Sliding menu under action bar tabs

Any ideas on how this could be done?

Note: I understand that I might be breaking some conventions and UI patterns here, and if it does not work at all, I'll look at alternatives. But I'd like to get this working first.

EDIT: See the below screen shot of the Google Play Music app that does exactly what I need. See @CommonsWare's answer below where he does agree that I might be breaking convention. But then given the Play Music app, it may not be altogether that rare either.

Proper navigation with tabs sliding correctly

Ahmad
  • 69,608
  • 17
  • 111
  • 137
Archit
  • 887
  • 2
  • 10
  • 19
  • how did you manage to get at least part of the navigation drawer above at some of the content for me it goes below the content – pt123 Nov 14 '13 at 12:57
  • @pt123: not sure what you mean by that. Things worked fine for me when I used a ViewPager and PagerTabStrip. See the answer below by CommonsWare indicated as correct. If things still don't work, I'd suggest posting a new question with some code and screenshots. – Archit Nov 18 '13 at 03:22
  • thanks for responding, but it's been sorted out – pt123 Nov 18 '13 at 05:40
  • http://stackoverflow.com/questions/23783496/how-to-slide-the-actionbar-along-with-the-navigationdrawer I hope this solves your issues . – Denny Mathew Jun 16 '14 at 10:28
  • You can see my solution at http://stackoverflow.com/a/43817281/6112256 and it works perfectly. – Orlay Garcia Duconge May 06 '17 at 06:08

10 Answers10

22

you can use below libraries to get navigation model similar to Google play music app.

  • ActionBarSherlock (github)
  • nested-fragments (github)
  • PagerSlidingTabStrip (github)
  • NavigationDrawer (Android developer site)
  • Latest Support v4 library

I have created a project Navigation Drawer with Tab Strip Example at github, have a look at it.

Below is the screenshot of it.

Navigation-drawer-page-sliding-tab-strip

Balaji
  • 1,619
  • 15
  • 19
  • Thanks Balaji! Not that I need to use this immediately, but does the example you have put up have a dependency on ActionBarSherlock? Can it be done without that? Just checking. – Archit Aug 06 '13 at 14:28
  • @archit yes it depends on ActionBarSherlock and yes the project can be developed without it as google released updated support library – Balaji Aug 06 '13 at 15:21
  • @Balaji how can it be implemented without the use of ActionBarSherlock? – Sheharyar Nov 13 '13 at 00:00
  • @SheharyarNaseer hope you aware of google's v7 appcompat library, is this the one you are looking for? – Balaji Nov 13 '13 at 09:38
  • @Balaji I have implemented this UI and I'm having an issue which describe [here](http://stackoverflow.com/questions/20067762/sherlockfragment-oncreateoptionsmenu-is-not-calling). Can you please help me – AnujAroshA Nov 19 '13 at 12:30
  • @Balaji can you update your library using android action bar? – Swap-IOS-Android Nov 04 '14 at 13:01
  • @Balaji thank you for you wonderful project sharing with us, but i have a problem, how can i change the first tab to be the one in right? – Mr.Ghamkhar Dec 16 '14 at 19:41
11

Any ideas on how this could be done?

Do any of the following:

  • Switch away from action bar tabs, perhaps to ViewPager and a tabbed indicator (PagerTabStrip, TabPageIndicator from ViewPageIndicator)

  • See if an existing third-party drawer implementation has not yet updated to the new UI standards

  • Fork DrawerLayout and modify it to suit

  • Roll your own navigation drawer from scratch

I understand that I might be breaking some conventions and UI patterns here

Correct.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • In light of the fact the above design does depart from conventions ( and I'd rather not ) , I do have a case for doing so, where the sliding drawer menu acts as top level navigation, and the tabs are navigation within a section of the app. I'd rather not force the user to go one level up to be able to access top level navigation. Any suggestions on a better navigation scheme? – Archit Jun 05 '13 at 21:42
  • So far the only place where I've seen a sliding drawer menu implemented alongside action bar tabs is the new Google Play Music app (in the My Library section), and it does work as expected, with the menu sliding over the tabs, instead of under them. – Archit Jun 05 '13 at 21:43
  • 1
    @Archit: Google Play Music is not using action bar tabs. It is using a `HorizontalScrollView` around a `LinearLayout` and a set of `TextView` widgets for "My Library" tabs above the `ViewPager`. I'm not sure where else in Play Music tabs are used -- that's the only spot I'm seeing. If you want the Google Play Music approach, I'd use a `ViewPager` and a suitable indicator. – CommonsWare Jun 05 '13 at 22:15
  • And that is how navigation drawer now works in material design, so no rules are broken. – Dmitry Zaytsev Oct 02 '14 at 09:58
3

Check also this library http://www.androidviews.net/2013/04/pager-sliding-tabstrip/ The guy did a great job. You can use it with a navigation drawer and it works perfectly.

alecnash
  • 1,750
  • 1
  • 18
  • 42
  • I did follow your the answer you posted on a similar question. :-) I eventually went with the PagerTabStrip, which served my purpose well. But thank you for the link! – Archit Aug 06 '13 at 14:25
3

Finally, a clean way to achieve navigation drawer over sliding tabs in this blog http://www.paulusworld.com/technical/android-navigationdrawer-sliding-tabs

user2814778
  • 296
  • 6
  • 14
1

This can be done WITHOUT a Third party library. Check out Google's Sliding Tabs samples

     SlidingTabsBasic:   http://developer.android.com/samples/SlidingTabsBasic/project.html
     SlidingTabsColors:  http://developer.android.com/samples/SlidingTabsColors/project.html

Also, check out this awesome link: http://manishkpr.webheavens.com/android-sliding-tabs-example/ Worked like a charm for me. :)

user3316561
  • 586
  • 1
  • 6
  • 14
0

I had the same problem, but the only solution I found was to use tabs inside the inner fragment (not fragmentActivity). I don't know if it was the best solution, the only problem i had was styling this tabs, for the rest, it works perfectly

xgc1986
  • 868
  • 6
  • 8
  • You could try using PagerTabStrip, which is what I went with eventually. I'm not too sure how much you might be able to re-style the PagerTabStrip, but it works pretty well. You get all the nice swipey views and tapping on them works as well. – Archit Jul 29 '13 at 16:31
0

I managed to achieve this requirement by setting the navigationMode inside OnDrawerClosed and onDrawerOpened functions. It is a temp fix since the tabs actually do not disappear immediately.

  public void onDrawerClosed(View view) {
          getActionBar().setTitle(mTitle);
          if(getActionBar().getTabCount()>0) //Add tabs when the fragment has it
          getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);               
                        ...
                    }

   public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);              
                    ..

                    }

If you have some fragments with tabs, and other without it don't forget to remove tabs onCreateView of fragment that does not have tabs.

 getActionBar().removeAllTabs();
user2814778
  • 296
  • 6
  • 14
  • That's an interesting hack.... you might still be better served by changing your design somewhat to fit the answer by CommonsWare above. But an interesting hack nonetheless! – Archit May 23 '14 at 20:05
  • that's fine but remove tabs and I just want the menu slide over the actiontab – Xenione Jun 23 '14 at 18:01
  • @Xenione not sure if you still have the problem or not. whatever, another perfect solution can be found below http://stackoverflow.com/a/26772874/2814778 :) – user2814778 Jan 12 '15 at 04:50
0

Actionbar Navigaton Drawer and SwipeTabs cant be used simultaneously. You should implement Navigation Drawer using Actionbar and swipetabs by simple Tabhosts. You can use Tabhost for tabs and use fragments for inside view of each Tab. Fragments should be used via viewpager to provide scrolling/swiping effect. Connect tabs and viewpager with eachother through their methods

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TabHost
    android:id="@+id/tabHost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <HorizontalScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            android:scrollbars="none" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >
            </TabWidget>
        </HorizontalScrollView>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <android.support.v4.view.ViewPager
                android:id="@+id/viewPager_home"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </FrameLayout>
    </LinearLayout>
</TabHost>

FAK
  • 13
  • 7
0

Play music does not use standard ActionBar.Tab Then you can implement your own tab container by extend HorizontalScrollView and work together with ViewPager

tarn
  • 546
  • 6
  • 10
0

I have use tabs inside fragment of drawer. I solve this problem adding

getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

in onDrawerClosed() and getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); in onDrawerOpend() method.

I hope this will help you.

Micho
  • 3,929
  • 13
  • 37
  • 40