Implementing ActionBarSherlock Side Menu Navigation Drawer in Android

  • Excelent!!!!

    Working perfect!!

  • Ariel

    I got DrawerLayout error, and doesn’t seem to be an import fix. Any ideas? i got ABS 4.3

    • Ariel

      I fixed it using your ABS project. Maybe Drawer doesn’t work on latest version of abs

      • Hi Ariel, I forget to mention in my tutorial post. You need to download the latest Support Library from Google Support Library. Use the latest support library in your ABS Library and project.

        • Ariel

          I downloaded Support Library but still doesn´t work. However it works with your ABS. Is there a way to make the fragments landscape? I got a tablet and the fragments takes only half screen. Thnxs!

          • Hi Ariel, I don’t have a physical Android tablet so I tried it on a tablet AVD. Everything seems okay to me. Take a look at the screenshot. Its running on API 15.

          • Ariel

            Thanks for the answers. As you see on the images (the firstone is the emulator, the second is the eclipse layout), the content is moving to the left side of the screen. I can’t figure out why.

          • Ariel

            Sorry for that i got it now. Befor i update the Support Library i was getting an error when i defined “match_parent” for layout width and height on the drawer xml file. So i had to put the size un pixels, like 800×400, so i changed that now and works great. Thank you very much man and by the way great job.

          • Your welcome 🙂

  • Ricardo García Fernández

    Great easy and very useful , thanks !

  • James Giomatti

    Is it possible to implement the back button to return to previous fragment in the MainActivity?

    • I think it is possible. I will see what I can do. 🙂

      • After some thorough googling. You can try this to close your drawer on the back button click. I’m still working on returning to previous fragment. To give it a try, add this portion of codes in your

        public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
        // Close Drawer on Back Key
        return super.onKeyDown(keyCode, event);

        • J Giomatti

          This is great. Thanks for a detailed tutorial.

          • I think the best approach is to close or open the navigation drawer on back key. Just my suggestion. 🙂

  • Amyth

    Your tutorial is the best I have come across on this topic. Excellent and I really mean it. I was looking for something good on this topic since a few days.

    I was trying to implement something similar in my code using ActionbarSherlock. The code is working well. The only issue is that I am not able to toggle the “up” caret next to my app icon when the navigation drawer is pulled out.
    You can checkout my query on SO.
    Kindly help if possible. Thanks.

    • Hi Amyth, may I know what do you mean by “up” caret?

  • Ariel

    Hi, it’s me again >D. Is there a way to call a SherlockFragment from another? For example, inside fragment3 i want a button that calls a fragment 4, that is not on the side menu. Thnx!

    • Hi Ariel, its nice to see you back. I’m not sure if this is what you need. Check out the codes below.

      First of all add a button into your fragment.

      Then use the code below in your fragment with the button you created.

      public class Fragment2 extends SherlockFragment {
      Fragment fragment1 = new Fragment1();
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      final View rootView = inflater.inflate(R.layout.fragment2, container,
      final View button = rootView.findViewById(;
      button.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
      FragmentTransaction ft = getSherlockActivity()
      ft.replace(, fragment1);
      return rootView;

      • Ariel

        Thanks very much for the answer! I got it working great.

  • Great tutorial, thanks!

    One issue, though, was that you accidentally used super.onDrawerClosed(View view) twice, making the animation in the action bar a little jumpy. Might wanna fix that 😉

    Also, your sample image for the shadow should be a 9patch. While the file appears 9patched, the filename doesn’t end with .9 🙂

  • Phil

    A nice tutorial that closely follows the Android docs.

    Unfortunately there is a small bug with it which I’ve not been able to resolve. When the drawer is pulled out the icon correctly animates, but once it reaches the final open position the icon snaps back to where it started.

  • Phil

    I came back to your example when I was having issues trying to highlight the selected item in the list and noticed you’re also making a similar call:

    mDrawerList.setItemChecked(position, true);

    I wondered if it was something to do with the added complexity in my list (I have header, footer, separaters) but it appears it also doesn’t work in your example.

    • Hi Phil, I’m not sure what your issue here. Could you please show us your codes? You can use if your codes are long and If you are concern about privacy you can email us your codes. 🙂

      • Phil

        If you see the attached images, the first is the Google demo app, you’ll see that the active fragment’s corresponding menu item remains highlighted, however on your demo it does not.

        I’ve even removed my custom adapter and used an ArrayAdapter with a CheckedTextView, but still cannot get highlighting to work with ABS.

        I’m just trying to get to the route cause of this issue and thought maybe you had noticed this with your demo. So far I can see that a number of ICS+ apps are working, Google nav drawer demo, Gmail, Google Play Music and that a number of ABS apps are not, your demo, my app.

        Not sure if it is relavent but It looks like Google Play Music is using ActionBarCompat now as it has ActionBar and Nav Drawer on Android 2.3 but unfortunately they still haven’t released this yet.

        I think the next step should probably be to try adding ABS to the Google demo and see what happens.

        • Hi Phil, I get what you mean now. Just insert this into your drawer_list_item.xml LinearLayout



          into your LinearLayout.

          Sample Below

          • Phil

            I got it working in API 11+ using this method after hacking up the Google planets demo app a bit, but still no solution for Android 2.x devices. It kinda defeats the point of using ABS at all if you can’t fully support Android 2.x!

            The home icon doesn’t work in 2.x either, it just displays the up carat.

            I’m sticking Android 2.x on the todo list for now and I’ll come back to it later when the app is finished, thanks for your input.

  • UnjiRohOwlRock

    wonderful code!! i was just searching for the guideline for navigation drawer. and this one is the best among all the google search list. Thanks it helped alot.

    • UnjiRohOwlRock

      Actually i got one question, lets say i want to put multiple seekbars in drawer, and I want to give all of them a different jobs. Since i only have one id for seekbar in drawer_list_item.xml, where should i code for my seekbars? or where should my code for seekbar supposed to go? Thanks!

      • Hie Unji, you can just code it in your class. 🙂

  • Anubhav

    Excellent tutorial.

  • Cali

    I am having a extremely hard time getting this to work. I imported the project and I keep getting this error I dont even know where Lcom is coming from im not defining that in the path. Also when I go through the debug process I get this error NativeStart.main(String[]) line: not available [native method]. Any help is greatly appreciated as I am also new to android development like many others on here.

    • Hi Cali, are you using the latest ActionBarSherlock Library and Support Library? or try using the ABS Library provided in the download. Follow the steps below.

      Step 1 : Download and Import both projects (ABS and ABSSideMenuTutorial) into your Eclipse.

      Step 2 : Right-click on SideMenuTutorial project and click properties.

      Step 3 : Import the ABS Library

      Step 4 : “Fix project properties” and “Clean” for both projects

      Step 5 : Restart Eclipse (This works for me)

      Let me know if you still have issues. Good Luck

    • Hi Cali, I have clean the projects for you, kindly please re-download the codes and follow the steps I mentioned on the previous post.

  • sinistance

    thanks! work awesome with holoeverywhere too.

  • Nicola Lombardi


    Wonderful tutorial, I will use this for my internship project.

    There is only one problem I can not resolve.
    The side menu is transparent, and I can see my fragments layout under it.
    In the demo it looks like the drawer comes above the fragment, I copied the code but still it looks like the drawer is beneath the fragment and not above it.
    I did some troubleshooting 😉 before I came to this conclusion, if I set a background color on one fragment I can not see the side menu. Meaning the drawer is beneath it right? But I tried the whole weekend trying to fix it but I can not figure it out. Can someone help me.

    Thank you very much in advance 🙂

    Nicola Lombardi

    • Nicola Lombardi

      Hi there,

      I finally found my error, I was replacing the wrong content for the fragment, oops x)

      • Hi Nicola, I’m glad this tutorial helped you. 🙂

  • Mau

    I have the new ActionBarSherlock library in my eclipse, with the support library rev 13. I downloaded this package and imported SideMenuTutorial. Then I added the support library to it and also referenced the ActionBarSherlock Library.

    I have no errors, but when i run it, i get “Unfortunately SideMenuTutorial stopped working” sign.

    Any ideas?? what am i doing wrong??

    Thanks, excelent tutorial btw.

    • Hi Mau, please do a “clean” on your project and the ActionBarSherlock Library. Then restart your Eclipse. To clean your projects, go to Project > Clean .

      Make sure your projects looks similar to the screenshot attached on this comment.

      If non of the above are working, try using ABS library I provided for you. Let me know if you need further assistance. 🙂

      • Richard

        I have the same problem I have no errors, but when i run it, i get “Unfortunately SideMenuTutorial stopped working” sign.

        I tried to Clean en almost everything looks te same only one thing different.

        I use your ABS library..

        Only different is android-support-v4.jar is’nt in the Referenced Libraries but it is Android private Libraries

        To fix this problem: from(!msg/adt-dev/epOfZbKPFdk/RbR2VYNQ5_8J)

        When upgrading, the ‘Order and Export’ of the new ‘Android Private Libraries’ is not always checked. And the android-support-v4.jar is now in this ‘Android Private Libraries’ section.

        To fix this, go to ‘Order and Export’ and check ‘Android Private Libraries’. Then refresh/clean/rebuild.

        After you done this ‘fix’ for a library project, you may need to just close and re-open any depending project, because they may not see this ‘fix’ immediately.

        See image!

        • Hi Richard, I feel your frustrations. Lets try it this way, temporary remove all the apps in your Eclipse. Then download a copy of this tutorial, then try to compile it again. Do the necessary “cleaning” and “Fix Project Properties”, then restart Eclipse. Let me know if you still having issues.

  • kawingtamtkw

    how can I change the words of the side bar according to the @string/XXX?

    • Hi kawingtamtkw, the side bar itself is a ListView. Doing that will require rewriting the whole source code. 🙂

  • kawingtamtkw

    I want to add an onClickListener in the, but there’s are some errors, How can I fix it?

    • Hi kawingtamtkw, we have previously written a tutorial about button click new activity example. You can check it out here . However, I will show you how to implement it. See below

      public class Fragment1 extends SherlockFragment {
      private Button button;
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment1, container, false);
      button = (Button) rootView.findViewById(;
      button.setOnClickListener(new OnClickListener() {
      public void onClick(View arg0) {
      // TODO Auto-generated method stub
      Toast.makeText(getSherlockActivity(), "Button Clicked",
      return rootView;

      • kawingtamtkw

        I’ve read your passage of “Android Button Click New Activity Example”, but it is still unsuccessful. Can you tell me how to fix it?
        Thanks a lot:))

        • Hi kawingtamtkw, I’m not sure if this is what you need. Check out the codes below.

          public class Fragment1 extends SherlockFragment {
          private Button button;
          Fragment fragment2 = new Fragment2();
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment1, container, false);
          button = (Button) rootView.findViewById(;
          button.setOnClickListener(new OnClickListener() {
          public void onClick(View arg0) {
          // TODO Auto-generated method stub
          FragmentTransaction ft = getFragmentManager().beginTransaction();
          ft.replace(, fragment2);
          return rootView;

          • kawingtamtkw

            How can I solve these problems?

          • Check your imports. 🙂

          • kawingtamtkw

            imports means?
            what imports should I add?

          • Try put this imports into your

            import android.os.Bundle;
            import android.view.LayoutInflater;
            import android.view.View;
            import android.view.View.OnClickListener;
            import android.view.ViewGroup;
            import android.widget.Button;

  • i.dragon

    Hi, I am a beginner in android.
    I notice that you use a textView and an imageView for your ListView item,
    I wonder if I could just simply use a textView but with drawable icons along the left hand side to achieve the same effect ,for example,in the getView(…) method :

    mtextView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.action_settings), null, null, null);

    any help will be appreciated.

    • Hi i.dragon, the left side menu drawer is written using a ListView, changing it will require rewriting the source code. You will have make your own changes. However, if you are having issues feel free to comment here. 🙂

      • i.dragon

        I got it and thanks! I had totally ignored that there is also another textView for a subtitle in your code. therefore an imageView fits well. By the way,the tutorial is wonderful.

  • Loui


    Will this work if I test it on device with android version 2.2.2?

    I haven’t been able to launch avds for a while now and I’ve tried everything from google. Maybe I missed something. Therefore I’ve been using my device to test projects.


    • Hi Loui, the lowest API tested is API10(Android 2.3.3). I will test others when I have time. 🙂

  • Pavlos

    Well i cant seem to get the proper Navigation Drawer icon on devices below ICS. I just get the usual ‘Up’ icon displayed on 2.3 and below

    • Hi Pavlos, I just realize that issue. Thanks for reporting. 🙂

      • Pavlos

        Is there any workaround? I have googled about it a lot and cant seem to find anything related.

        • Same here, I will post my updates here. Meanwhile, I will try to find help from other sources. 🙂

          • Cameron Voell

            Did either of you guys ever find another solution to the sliding navigation drawer icon not showing up on pre ICS with ActionBarSherlock? If I have to drop ABS just for the three little lines, I might cry. Thanks!

          • Hi Cameron, create a thread in our forum and discuss this matter over there. 🙂

        • Hi Pavlos, I found a temporary fix. Try the codes below.




          • Pavlos

            Nice one mate. Thank you i will apply it to my application and tell you.

    • anything new about it?

  • Rahul

    Hello sir just wanted to know can we implemented this drawer on bottom of the screen.

    • Hi Rahul, I don’t think its possible using navigation drawer. But there is an option, you can try create an actionbarsherlock options menu at the bottom, then set the menu to open fragments. 🙂

  • m1nd

    If I copy your project 1:1 and import it into eclipse I get errors that these 3 imports can’t be resolved:


    Do you know how to fix that? Everything should be updated and working fine. I’m really frustrated right now. I’m trying to fix that for hours now but nothing works..

    • Hi m1nd, check out the screenshot attached on this comment. You need to import the library from the ActionBarSherlock Library or copy the android-support-v4.jar from ABS library and paste it into SideMenuTutorial lib folder.

      • m1nd

        That did the job, everything works now.
        Thanks mate 😉

  • Arafayé

    Hi. Is there a way to use the Holo light theme on the drawer ? If i switch to Theme.Sherlock.Light.DarkActionBar i see the drawer black :/

    anyway awesome job 😉

    • Hi Arafaye, have you tried this? android:theme=”@style/Theme.Sherlock.Light”

  • Bradford

    I’m trying to get this going, however when I run I get the following error:


    I have no errors before it compiles, however as soon as my code references a DrawerLayout, it crashes. I wonder if it’s still using the old r7 code. I’m also using Maven.

    Any suggestions?

    • Hi Bradford, you have to use the latest Support Library. Try to use the ABS library provided in the download. 🙂

    • Bradford

      Nevermind, I found my problem. Maven was still using the old support-v4. I had to install the new one to my local repo using this command:

      mvn install:install-file -Dfile=android-support-v4.jar -DartifactId=support-v4 -Dversion=r13 -Dpackaging=jar

  • Matimu

    I want to add more items in the ListView but categories them e.g
    category 1 contains Fragment 1,2 and 3.
    category 2 contains Fragment 4,5 and 6.

    • Hi Matimu, check on this docs from Android. Expandable ListView is what you need. 🙂

      • Matimu

        Thanks i will get back at you soon

      • Matimu

        @AndroidBegin:disqus Unable to To separate The Title and Subtitle in the side menu in categories am getting the category name on top of every title how do i split it .

      • Matimu

        AndroidBegin On MenuListAdapter am able to pass mMenuAdapter = new MenuListAdapter(this, category,title,subtitle, icon);

        am unable to get the other two categories on the side menu

  • Anonymous

    Hi, I want to implement tabs into one of the fragments (like the new Google Play Music App does), but I can’t find the way to do it.

    Thanks 😉

    • Hi there, have you seen our previous tutorial regarding fragment tabs?

      • Anonymous

        Of course I’ve seen that tutorial, and I’ve tried also with ViewPager Tabs, but the problem is when I try to implement the “SherlockFragmentActivity” in one of the “” (this tutorial), because each “” must extends from “SherlockFragment” instead of


        • Hi there, try using getSherlockActivity().getSupportActionBar();

          In your

          public class Fragment1 extends SherlockFragment {
          // Declare Tab Variable
          Tab tab;
          public void onCreate(Bundle savedInstanceState) {
          // Create the Actionbar
          ActionBar actionBar = getSherlockActivity().getSupportActionBar();

          Let me know if this works 🙂

  • Liran

    Please answer this question:

    It seems that in order to open the drawer by using a gesture would work only if the touch starts from the most left side of the screen.
    How can I customize the area that would trigger this gesture , to move the navigation drawer?

    • Hi there, I’ll see what I can do. At the meantime, try googling or post a question regarding this on stackoverflow. 🙂

  • username

    Thanks for this great tutorial.I have one question though.Instead of a TextView I want to display an ImageView but I cant get it to work, the ImageView isn’t displayed at all.The image I want to use is located on the sd card in my device.I’ve been working on this for days now 🙁 I hope you can help me.

    • Hi there, if you are looking at the source code. The listview that is used for the menu contains images that is located in your res folder. You can change any images you want from there. 🙂

      • username

        🙂 thats not what I meant.I want to add an ImageView in the “fragment1.xml” for example.Any idea why it is not working for me?Thanks for your quick answer 🙂

        • Hi there, try the codes below. Let me know if its working for you. 🙂

          public class FragmentTab1 extends SherlockFragment {
          ImageView image;
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragmenttab1, container, false);
          image = (ImageView) getSherlockActivity().findViewById(;
          return rootView;

          • username

            Gives me a null pointer exception :S caused by the line image.setImageResource(R.drawable.image).

          • Hi username, did you manage to show the image when you use the rootView? 🙂

          • username

            I tried that too, once in the onCreateView and once in the onActivityCreated. Both methods ended up not showing the ImageView,however a TextView or a simple Button is displayed.This is driving me nuts lol 😀

          • Ok, I’ll test my codes again. 😛

          • username

            To sum up getSherlockActivity -> null pointer exception, rootView -> no image.Thanks so much for your time so far.This is a really important project to me.

          • username

            Finally!I figured it out myself and guess what,of course it was my fault.I wrote a piece of code to get the filename with the path from the image located on the sd card.There was the problem for some reason.Thanks so much for your time 🙂

          • Changing it to rootView seems working for me. I’ve edited my comment above. Thanks

  • Is there a way to support


    in your drawer_list_item.xml layout?

    in 2.3 using Actionbar Sherlock? Do you have a tutorial that shows how to display the selected navigation drawer item? Thank you, and great tutorial.

    • Hi Francisco, insert this into your drawer_list_item.xml LinearLayout to get it Highlighted.



      into your LinearLayout.

      Sample Below

  • Salim Yego

    Am trying to load a listviev on the fragment when an item on the side menu is clicked but am having a problem..the listview is populated from a json array…i already have the class generates the listview and is working do i intergrate it?

    • Tharaka Nirmana

      I am also having the same issue, I found out that the original layout items below the slider prevent items from touching. I cant find a solution. Any tip?

  • VenomVendor

    Can you give an example of having tabs in Menu?
    Reference image,

  • GianMarcoDiFrancesco

    hi i have fragment with gps status and info but the fragment re-create every time when pass from another fregment to this….how keep state of my fragment whitout re create it?

  • Wasseem Bazbaz

    this tutorial was a great help.
    But am facing an issue the fragment i made gets recreated for example if am doing something with current fragment like running something a new fragment is made some help pleasE ?

    • Hi Wasseem, I’ll try to figure it out. 🙂

  • Francisco Rojas Morales

    Hi! how i could return a map fragment in this tutorial?

  • Kynkeniven Grosskopf

    Hi, I’m having a problem in drawer_lis_item.xml

    on android:background=”?android:attr/activatedBackgroundIndicator”

    it says “requires API level 11 (current min is 8)”

    if I remove that line, my tabs get untidy

    O my device runs ok with that line,

    but in device with 2.3 or less get “android.view.InflateException: Binary XML file line #2: Error inflating class ”

    can you help me?

    • Hi Kynkeniven, thanks for your feedback. I will look into it.

      • leo_lv

        Hi, I also have the same problem, and I was by changing the background listview item is selected to achieve the effect,I hope you have a better way

  • DroidNoob

    How would you have the button displayed on the right side and open from right to left?

  • sakthidasan

    if i click one button.. the menus are open as slide from left to right for example(picart app)
    .. and then i want create my menus are vertical if i click any one menu will open the submenu from right to left as slide movement
    if u have answer pls help me

  • Ivan

    How can I add “headers” to the drawer menu? I need to add 3 headers for my drawer’s list.

  • Petar Papalevski

    I found a solution for the force close in android 2.3. Just delete this two lines in drawer_list_item.xml


    • mahmut efe

      Thank you so much Petar Papalevski. I deleted related lines and it worked on android 2.3 version.

    • Çağrı Çakır

      Great catch! I’ve checked the attr/ path in integrated sherlock project inside my project and those attributes were already defined in it. What is the reason that such a mix comes up? Regards.

  • magnificat

    Hello and thank you for this great tutorial!

    How can I add a Webview in fragments ?

  • mahmut efe

    this sample code is not working on old version. i tried on 2.2 and 2.3. it didnt worked. but it is working on 4.0 and upper.

  • Alan Dwi Prasetyo

    eror 🙁

  • Alan Dwi Prasetyo

    eror, is there anything wrong?

  • Frank


    absolute great tutorial. Thanks for sharing 🙂
    One question: Is a category also possible?


    • mitsus

      Hi, have you solved about category? If yes can you shere your solution? Regards

      • Hi, I’ll prepare a tutorial on that. Stay tuned. 🙂

  • Alexmuller1416

    how to use intent in the project

  • Esteban Butti

    Hey! I’m trying to put some of the side menu options on the bottom of the menu, so I should have 2 lists, one on the top and other on the bottom. Can you guide me on how to achieve that? Thanks in advance.

  • HG

    this dont work

  • Ejumu Emma

    very good but when are coming up with that of categories thankyou

  • Tharaka Nirmana

    Working fine, thank you!. But there is a problem. When I click on an item, the layout below the slider prevents slider items being clicked, when I remove all below layout elements, slider items are clickable. Please help!

  • Mahdi Kenji

    how can make slide menu right of screen?

  • Capkin

    hi, thanks for the tutorial it’s very good. But I have a question how can I add to this app Imageloader form Internet. thanks a lot

  • Aazam Khan

    Hiii nice tutorial but i want both side (left drawer and right drawer ) plz help me out ..

  • I’m using sherlock actionBar and I set a customView to the actionBar. So I have one strip that contain the drawer icon and my custom view, and another strip with the tabs of the action bar.
    How do I change the background color of the drawer icon? it’s not the same as the tabs’ color.

  • Mahdi Kenji

    thanks a lot. it was cool tutorial. but can we make this menu right to left?

  • How do when swipe,nav drawer swiped with action bar
    Like this

  • nilesh kansal

    How do when swipe,nav drawer swiped with action bar
    Like this

  • Faisal

    i am new in android. if we want this side menu in every activity, then do we have to do this in each activity?

  • premanshu

    i am a beginner and hoping to resolve a issue what i observed at