1

I'm trying to achieve the effect of moving the whole actionbar together with it's content upon showing the navigation drawer on either click or slide. I'm using the ActionBar compat provided and implemented a Navigation Drawer upon creating project and what I have is that the Nav drawer appears as default meaning it's slide below the ActionBar and covering the content. What I wanted to achieve is something like this:

enter image description here

I'm a bit new on customization of Navigation bar and my searches so far doesn't give the the result I'm looking for so hope someone can help me on this. Hope there's a simple way to achieve this without using any Libraries.

KaHeL
  • 4,301
  • 16
  • 54
  • 78

1 Answers1

0

Override the navigation drawer like this.

 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
 mDrawerList = (ListView) findViewById(R.id.left_drawer);
 frame = (FrameLayout) findViewById(R.id.content_frame);

 mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.acc_drawer_open, R.string.acc_drawer_close) 
    {            
        @SuppressLint("NewApi")
        public void onDrawerSlide(View drawerView, float slideOffset)
        {
            float moveFactor = (mDrawerList.getWidth() * slideOffset);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) 
            {
                frame.setTranslationX(moveFactor);
            }
            else
            {
                TranslateAnimation anim = new TranslateAnimation(lastTranslate, moveFactor, 0.0f, 0.0f);
                anim.setDuration(0);
                anim.setFillAfter(true);
                frame.startAnimation(anim);

                lastTranslate = moveFactor;
            }
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
Yugesh
  • 4,030
  • 9
  • 57
  • 97
  • Hi, thanks for the answer but I have a few comments about this. 1st is that I have implemented a navDrawer using android default resources meaning I'm not sure about the part of the mDrawerList since the list for the drawer is attached to the fragment (NavigationDrawerFragment) and I think that will result into nullpointer based on what I currently have. Second is that I'm using an overlayed ActionBar since I need it to be translucent and so I'm not sure if this will also move my actionbar on display of navDrawer. Lastly is that I'm not sure on how should I implement it. haha! Please help. – KaHeL Aug 11 '14 at 03:59
  • Hi, okay so I already got on how I should implement it now the only problem is that the actionbar doesn't move although the content does. I tried removing the ActionBarOverlay style but still get the same result. Not sure about what cause it. – KaHeL Aug 11 '14 at 05:52
  • [Here](http://stackoverflow.com/questions/11234375/how-did-google-manage-to-do-this-slide-actionbar-in-android-application) you will find solution. – Yugesh Aug 11 '14 at 06:10
  • oookay, now I'm lost again. haha! – KaHeL Aug 11 '14 at 06:59