Xamarin.Forms Hamburger Menu Icon gone after Update to Xamarin.Forms 2.2

随声附和 提交于 2020-01-02 03:40:26

问题


After I updated my Xamarin.Forms project from Xamarin.Forms 2.0 to Xamarin.Forms 2.2, the Hamburger Icon is gone.

I've googled without luck, has anybody experienced the same issue?


回答1:


If the default icon has disappeared you can set your own icon of the Master page for example:

public class MasterPage : MasterDetailPage
{
    FlyOutMenuPage menu = new FlyOutMenuPage ();
    Master = menu;
}

public class FlyOutMenuPage : ContentPage
{
    Icon = "menu.png";
} 

And menu.png is a resource image, you can get lots of icon from here:

https://www.iconfinder.com/search/?q=hamburger&price=free




回答2:


Mine was hidden in Android, so I had to write a custom renderer to apply a color and set the opacity to show it again:

[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustomNavigationRenderer))]

namespace App.Droid
{
    public class CustomNavigationRenderer : NavigationPageRenderer
    {

        public CustomNavigationRenderer(Context context) : base(context)
        {
        }

        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);
            var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            for (var i = 0; i < toolbar.ChildCount; i++)
            {
                var imageButton = toolbar.GetChildAt(i) as ImageButton;

                var hamburger = imageButton?.Drawable as DrawerArrowDrawable;
                if (hamburger == null)
                    continue;

                hamburger.Color = Context.GetColor(Resource.Color.primary_text_default_material_light);
                hamburger.Alpha = 255;
            }


        }
    }
}


来源:https://stackoverflow.com/questions/36933602/xamarin-forms-hamburger-menu-icon-gone-after-update-to-xamarin-forms-2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!