1

I'm using fragment based navigation, each fragment has it's own toolbar.

When navigating to a fragment I want the back button to display in the toolbar.

I have overridden the OnCreateView method as follows:

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
   var ignored = base.OnCreateView(inflater, container, savedInstanceState);
   var view = this.BindingInflate(_fragmentId, null);
   _toolbar = view.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
   if (_toolbar != null)
   {
      ParentActivity.SetSupportActionBar(_toolbar);
      ParentActivity.SupportActionBar.Title = _title;
      ParentActivity.SupportActionBar.SetDisplayHomeAsUpEnabled(true);
      _drawerToggle = new MvxActionBarDrawerToggle(
         Activity,
         (ParentActivity as MainView).DrawerLayout,
         _toolbar,
         Resource.String.drawer_open,
         Resource.String.drawer_close);

      (ParentActivity as MainView).DrawerLayout.AddDrawerListener(_drawerToggle);
   }

   return view;
}

SetDisplayHomeAsUpEnabled(true) should be changing the button to the back button, according to numerous other stack overflow answers, However this is not working as can be seen in the following screenshot:

back button not shown

I have checked that the SetDisplayHomeAsUpEnabled(true) line is hit when I navigate to the fragment.

For reference I am using Xamarin with MvvmCross.

How do I make change the toolbar to the up/back button when using fragment based navigation?

trampster
  • 8,598
  • 4
  • 37
  • 52

2 Answers2

1

Solved it:

The DrawerToggle was somehow overriding the toolbar settings. Adding the following line fixes the problem.

_drawerToggle.DrawerIndicatorEnabled = false;
trampster
  • 8,598
  • 4
  • 37
  • 52
0

I'm not very familiar with Xamarin. Try setting the indicator with ParentActivity.SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu_white_24dp);. This might help.

trampster
  • 8,598
  • 4
  • 37
  • 52
Monu Surana
  • 694
  • 1
  • 6
  • 20