Search code examples
androidandroid-fragmentsnavigationnavigation-drawerback

DrawerToggle backbutton setting in android navigation drawer/action bar


I am using android v4 drawer toggle for implementing the navigation drawer.

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.drawable.menu_logo, R.string.drawer_open,
                R.string.drawer_close)

My problem is when I click on the navigation drawer icon I opened one drawer layout(list). If I click on any of the item i am navigating to that fragment. Here is my code.

case 1:
fragmentPopped = fragmentManager.popBackStackImmediate(
                    NewBikeSearchFragment.TAG, 0);

            if (!fragmentPopped
                    && fragmentManager
                    .findFragmentByTag(NewSearchFragment.TAG) == null) {

                ft.setCustomAnimations(R.anim.grow_from_middle, R.anim.fade_out);

                NewSearchFragment newfragment = new NewSearchFragment();

                ft.replace(R.id.content_frame, newfragment,
                        NewSearchFragment.TAG);
                ft.addToBackStack(NewSearchFragment.TAG);
                ft.commit();
            }

For that fragment navigation I want to change R.drawable.menu_logo to back icon . I have googled some tutorials and examples but I didn't succeed. Can you please give an idea how can I do this task in the V4.


Solution

  • Please try to call

    getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
    

    from your fragment

    If that isn't enough, add this line

    getActivity().getActionBar().setHomeAsUpIndicator(R.drawable.ic_back_button);