How to hide/disable the hamburger icon for Android.

Huynh Than 65 Reputation points
2024-01-28T03:03:01.5866667+00:00

Hi, I'm Daniel, and I'm using MAUI as a migration from Xamarin. On Android, I have a FlyoutPage that looks like this. User's image

I used it to navigate 2 times to reach a page as shown below, please don't mind the title of the Page. It has a different content. User's image

However, when I tap on back button, it pops up the flyout page instead of letting me go back to the previous page. The flyout behavior is popovers, so it doesn't need the hamburger icon to pop up the flyout page. Swiping is just enough. On Xamarin, this back button works just fine. I wonder if we have a way to disable that icon in MAUI?

Developer technologies .NET .NET MAUI
Developer technologies .NET Other
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-01-30T05:52:33.2033333+00:00

    Hello, If you use flyoutpage, you can hide the hamburger button by adding a ToolbarHandler in your android platform folder.

    using Google.Android.Material.AppBar;
    
    namespace MauiApp6.Platforms.Android
    {
        internal class ToolbarHandler : Microsoft.Maui.Handlers.ToolbarHandler
        {
            protected override void ConnectHandler(MaterialToolbar platformView)
            {
                Toolbar toolbar=VirtualView as Toolbar;
                toolbar.DrawerToggleVisible = false;
                (VirtualView as Toolbar).PropertyChanged += ToolbarHandler_PropertyChanged;
                base.ConnectHandler(platformView);
            }
    
    
           protected override void DisconnectHandler(MaterialToolbar platformView)
            {
                (VirtualView as Toolbar).PropertyChanged -= ToolbarHandler_PropertyChanged;
                base.DisconnectHandler(platformView);
            }
    
    
           private void ToolbarHandler_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                if (sender is not Toolbar toolbar || !toolbar.DrawerToggleVisible)
                {
                    return;
                }
                toolbar.DrawerToggleVisible = false;
            }
        }
    }
    

    Then please register this handler in your MauiProgram.cs..

       builder
                    .UseMauiApp<App>()
                    .ConfigureMauiHandlers(handlers =>
                    {
    #if ANDROID
                        handlers.AddHandler<Toolbar, MauiApp6.Platforms.Android.ToolbarHandler>();
    
    #endif
                    })
    

    Best Regards, Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.