Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

[Material] how to gain access to `Toolbar` from custom renderer?

$
0
0

Based on @TheRealJasonSmith's gist on how to add Material design to your Forms.Android app, I've implemented the "Toolbar" instead of the "ActionBar".

I'm wondering how I might go about getting access to that View in order to set the NavigationIcon to the Page.Icon?

Right now I've got a custom renderer that is attempting to set the Toolbar NavigationIcon like so, but toolbar is always null

[assembly: ExportRenderer(typeof(Page), typeof(Renderers.ExtendedPageRenderer))]
namespace Renderers
{
    public class ExtendedPageRenderer : PageRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);

            if (Element != null && Element.Icon != null)
            {
                var iconId = ResourceManager.GetDrawableByName(Element.Icon.File);
                var toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
                if (toolbar != null)
                {
                    toolbar.SetNavigationIcon(iconId);
                }
            }
        }
    }
}

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>