-1

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.

Shankar
  • 269
  • 4
  • 17

2 Answers2

1

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);
orelzion
  • 2,452
  • 4
  • 30
  • 46
0
public static boolean isHomeFragment = true;

In the Fragment write this code

MainActivity.actionBar.setDisplayHomeAsUpEnabled(true);
        MainActivity.actionBar.setHomeAsUpIndicator(R.drawable.ic_action_navigation_arrow_back);
        MainActivity.isHomeFragment = false;

In the Home Fragment write this code

MainActivity.isHomeFragment = true;
            MainActivity.actionBar.setDisplayHomeAsUpEnabled(true);
            MainActivity.actionBar.setHomeAsUpIndicator(R.drawable.menu_logo);

In the mainactiviity write this logic. this is perfect.

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:

            if (isHomeFragment) {
                if (mDrawerToggle.onOptionsItemSelected(item)) {
                    return true;
                }
            }
            else
            {
                onBackPressed();
            }
            break;
        default:
            break;
        }

        return super.onOptionsItemSelected(item);
    }
Shankar
  • 269
  • 4
  • 17