Search code examples
xamarinxamarin.formsback-buttonapp-shell

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.


Solution

  • 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