9

I have following design in my project - Activity (which have menuitems A, B, C, D) if we click on menuItem A then a FragmentA opens.I'm adding this fragment on top of activity, So toolbar remains same. FragmentA onCreateView is -

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            rootView =  inflater.inflate(R.layout.fragment_a, container, false)

            Activity.toolbar.setTitle("FragmentA");
            Activity.toolbar.setNavigationIcon(R.drawable.back_icon);

            Activity.toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Activity.fragmentManager.popBackStack();
                    Activity.toolbar.setTitle("Activity");
                }
            }); 
}

So Basically in FragmentA I inflate Back Navigation Icon on toolbar. but i want to hide this icon when switch back to my Activity. I don't have any navigation icon or logo in Activity.

Vikram
  • 748
  • 2
  • 8
  • 22

2 Answers2

23

Try setting the NavigationIcon to null while getting back to activity.

Activity.toolbar.setNavigationOnClickListener(new View.OnClickListener( {
    @Override
    public void onClick(View view) {
        Activity.fragmentManager.popBackStack();
        Activity.toolbar.setTitle("Activity");
        Activity.toolbar.setNavigationIcon(null);
    }
}); 
darkprince92
  • 396
  • 3
  • 10
3

This is working fine with me:

getSupportActionBar().setDisplayHomeAsUpEnabled(false);

hope it helps somebody