I am trying to work out how to show the "up" arrow in Xamarin.Forms without a pushing a page onto the stack. I.E. I just want to perform an action when the back button is pressed. I am completely stuck on this so any help would be appreciated.
I have tried creating a custom renderer which handles a view property called DisplayHomeAsBack
. Which in the renderer calls the following:
FormsAppCompatActivity context = ((FormsAppCompatActivity)Forms.Context);
Android.Support.V7.App.ActionBar actionBar = context.SupportActionBar;
if (actionBar != null)
{
actionBar.SetDisplayHomeAsUpEnabled(element.DisplayHomeAsBack);
}
Unfortunately it seems this does absolutely nothing, even though all online tutorials and stackoverflow question for android suggest this method.
The plan is that I can then use the "OnBackButtonPressed" override in MasterDetailPage, which should allow me to perform this action. Unfortunately displaying the back button has been the larger hurdle so far!
Any idea of a better way to do this or how I can get the current mechanism to work?
EDIT
I have created a project and uploaded it to this question on the Xamarin support forums, if it helps. http://forums.xamarin.com/discussion/comment/186330#Comment_186330
MasterDetailPage
which I assume is in aNavigationPage
? Also, is thisMasterDetailPage
the first page in the navigation stack or do you have to click through other pages to get to it? Finally, you just want to change the action that is performed when you click it as opposed to changing what the button actually looks like correct? – hvaughan3OnOptionItemsSelected
inMainActivity
? You could figure out which menu item Id to check for, then use theMessagingCenter
to signal that it is time to do your custom action and returnfalse
inOnOptionItemsSelected
to signify that you are handling it yourself. If that does not work then you may have to override the default back button and implement your own. – hvaughan3OnCreateOptionsMenu
to change the way the icon looks as well as acts when clicked. When I have a chance I can post an answer with what myOnCreateOptionsMenu
looks like though, I am adding a custom icon and not just trying to re-add the arrow so it might be a little different. I guess you could also just push a new page onto the screen but it would look the exact same only it had your custom view showing... then you would get the back button and it would function – hvaughan3