Wiktor Kęska
Wiktor Kęska

Reputation: 561

How to hide back button in navigation bar using Xamarin.Forms - AppShell?

Currently I'm using AppShell in my xamarin app. I need to hide back button arrow in NavBar and replace it with menu icon. NavigationPage.HasBackButton="False" Isn't working for me.

Upvotes: 1

Views: 1584

Answers (1)

Wendy Zang - MSFT
Wendy Zang - MSFT

Reputation: 10978

You could use the custom renderer to reset the NavigationIcon. I use a star icon for reference.

[assembly: ExportRenderer(typeof(AppShell), typeof(ShellCustomRenderer))]
namespace ShellDemo.Droid
{
public class ShellCustomRenderer : ShellRenderer
{
    public ShellCustomRenderer(Context context) : base(context)
    {

    }

    protected override IShellToolbarAppearanceTracker CreateToolbarAppearanceTracker()
    {
        return new ToolbarAppearance();
    }         

}

public class ToolbarAppearance : IShellToolbarAppearanceTracker
{
    public void Dispose()
    {

    }

    public void ResetAppearance(Android.Support.V7.Widget.Toolbar toolbar, IShellToolbarTracker toolbarTracker)
    {
        //toolbar.SetBackgroundColor(Android.Graphics.Color.Red);
        toolbar.SetNavigationIcon(Resource.Drawable.star_small);// Resource.Drawable.star_small;
    }

    public void SetAppearance(Android.Support.V7.Widget.Toolbar toolbar, IShellToolbarTracker toolbarTracker, ShellAppearance appearance)
    {
        //toolbar.SetBackgroundColor(Android.Graphics.Color.Red);
        toolbar.SetNavigationIcon(Resource.Drawable.star_small);
    }
}

}

enter image description here

Upvotes: 2

Related Questions