animekun
animekun

Reputation: 1869

How to change Xamarin back button in menu bar?

this is what I have:

enter image description here

this is what I want to get:

enter image description here

If there is no pages in navigation stack, then title icon will be in left corner, else there will be back arrow and "Back" text. I didn't find any options to customize it, is it possible at all?

Upvotes: 3

Views: 8321

Answers (2)

Daniel Luberda
Daniel Luberda

Reputation: 7454

You can change arrow to hamburger icon if you use your MasterPage within NavigationPage:

Detail = new NavigationPage(masterPage);

If you want to hide icon - it only applies to Android. It can be solved with custom renderer (http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/):

[assembly:ExportRenderer (typeof(NavigationPage), typeof(CustomNavigationRenderer ))]
public class CustomNavigationRenderer : NavigationRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
    {
        base.OnElementChanged (e);

        var actionBar = ((Activity)Context).ActionBar;
        actionBar.SetIcon (Resource.Color.Transparent);
    }
}

To change icon, just change project files:

  • YourProject/Resources/drawable/icon.png
  • YourProject/Resources/drawable-hdpi/icon.png
  • YourProject/Resources/drawable-xhdpi/icon.png
  • YourProject/Resources/drawable-xxhdpi/icon.png

or on your MasterDetailPage set Icon property to another resource.

Upvotes: 3

chad
chad

Reputation: 737

use the static method SetTitleIcon on the NavigationPage object.

Upvotes: 0

Related Questions