androiddrawerlayoutnavigation-drawerandroid-actionbaractivity

Move action bar along with Navigation Drawer


I have implemented Navigation bar as per google guildlines but i want to move action bar along with drawer. I have even referred following How to slide the ActionBar along with the NavigationDrawer but not able to achieve it.

i want to achieve something like below without using third parties lib:

enter image description here

DrawerActivity:

public  abstract class BarcodeBaseActivity extends ActionBarActivity {

 @Override
    protected void onCreate(Bundle savedInstanceState) {

 setSupportActionBar(toolbar);
//        setTypface();

        mTitle = getTitle();
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
//        drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

        mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open,
                R.string.navigation_drawer_close) {
            public void onDrawerClosed(View view) {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                supportInvalidateOptionsMenu();
                history.setSelected(false);
                help.setSelected(false);
                unipoints.setSelected(false);
                promotions.setSelected(false);
                notifications.setSelected(false);
                info.setSelected(false);
                contact.setSelected(false);
                signout.setSelected(false);
                drawerOpened = false;
            }

            public void onDrawerOpened(View drawerView) {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                supportInvalidateOptionsMenu();
                getSupportActionBar().setTitle(mTitle);
                history.setSelected(true);
                help.setSelected(true);
                unipoints.setSelected(true);
                promotions.setSelected(true);
                notifications.setSelected(true);
                info.setSelected(true);
                contact.setSelected(true);
                signout.setSelected(true);
                drawerOpened = true;
            }

            public void onDrawerSlide(View drawerView, float slideOffset) {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                supportInvalidateOptionsMenu();
            }
        };
        drawerLayout.setDrawerListener(mDrawerToggle);
        mDrawerToggle.setDrawerIndicatorEnabled(false);
        mDrawerToggle.setHomeAsUpIndicator(R.drawable.burger);
        ValueAnimator anim = ValueAnimator.ofFloat(0, 1);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float slideOffset = (Float) valueAnimator.getAnimatedValue();
                mDrawerToggle.onDrawerSlide(drawerLayout, slideOffset);
            }
        });
        anim.setInterpolator(new DecelerateInterpolator());

// You can change this duration to more closely match that of the default animation.
        anim.setDuration(500);
        anim.start();
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                drawerLayout.openDrawer(Gravity.LEFT);
            }
        });

        drawerLayout.setDrawerListener(mDrawerToggle);
        mDrawerToggle.syncState();
//        drawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));

        drawerList = (ListView) findViewById(R.id.drawer_list);
        View list_header = getLayoutInflater().inflate(R.layout.drawerlist_header, null);
  drawerItems = getDrawerItems(pos);
        drawerList.setAdapter(new DrawerListAdapter(this, getLayoutInflater(), drawerItems));
        drawerList.setOnItemClickListener(new DrawerItemClickListener());


        if (drawerOpened) {
            history.setSelected(false);
            help.setSelected(false);
            unipoints.setSelected(false);
            promotions.setSelected(false);
            notifications.setSelected(false);
            info.setSelected(false);
            contact.setSelected(false);
            signout.setSelected(false);
        } else {
            history.setSelected(true);
            help.setSelected(true);
            unipoints.setSelected(true);
            promotions.setSelected(true);
            notifications.setSelected(true);
            info.setSelected(true);
            contact.setSelected(true);
            signout.setSelected(true);
        }

        setTitle(mTitle);
    }

  @Override
    public void setTitle(CharSequence title) {
        mTitle = title;
        getSupportActionBar().setTitle(mTitle);
    }


 private class DrawerItemClickListener implements ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(BarcodeBaseActivity.class.getSimpleName(), "Drawer item clicked at position " + position);

            /*for (DrawerItem drawerItem : drawerItems) {
                drawerItem.setSelected(false);
            }

            DrawerItem drawerItem = drawerItems.get(position - 1);
            drawerItem.setSelected(true);

            HeaderViewListAdapter headerViewListAdapter = (HeaderViewListAdapter) drawerList.getAdapter();
            DrawerListAdapter drawerListAdapter = (DrawerListAdapter) headerViewListAdapter.getWrappedAdapter();
            drawerListAdapter.notifyDataSetChanged();
*/
            selectItem(position);
            for (DrawerItem drawerItem : drawerItems) {
                drawerItem.setSelected(false);
            }
            if (position > 0) {
                DrawerItem drawerItem = drawerItems.get(position - 1);
                drawerItem.setSelected(true);

            }
            updateDrawer();
            SharedPreferences.Editor sharedPreferences = getSharedPreferences(AppConstants.PREFERENCE_SHARED_PREF_NAME, Context.MODE_PRIVATE).edit();
            sharedPreferences.putInt(AppConstants.PREFERENCE_LAST_DRAWERITEM_CLICKED, position - 1);
            sharedPreferences.commit();
        }
    }

Please help me with some snippet.


Solution

  • Use SlidingPanelayout provided by Android instead of using Navigation Drawer.

    https://developer.android.com/reference/android/support/v4/widget/SlidingPaneLayout.html

    http://www.survivingwithandroid.com/2013/10/android-slidingpanelayout-tutorial-2.html