HiMesh NaGar
HiMesh NaGar

Reputation: 105

How to add an icon in navigation bar for navigation page in xamarin forms for android?

I have made simple navigation pages. Now I want to add icon for android in navigation bar.

I added an screenshot and highlighted with black circle where i want to add an icon. enter image description here

I also tried custom renderer.
That is provided answer from this post: Change icon on Navigation bar - Xamarin.Forms Android

But not worked for me.
Here it is

enter image description here

Upvotes: 0

Views: 6918

Answers (3)

Benoist LUGNIER
Benoist LUGNIER

Reputation: 101

Thank you Dilmah.

It work for me. With Xamarin.Forms 2.5, I change the constructor by

public CustomMapRender(Context context) : base(context)

to avoid warning of obsolete constructor.

Upvotes: 0

Dilmah
Dilmah

Reputation: 1127

[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomMapRenderer))]
namespace XamarinFormsMaps.Droid
{
    public class CustomMapRenderer : NavigationPageRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
        {
            base.OnElementChanged(e);
            var bar = (Android.Support.V7.Widget.Toolbar)typeof(NavigationPageRenderer)
            .GetField("_toolbar", BindingFlags.NonPublic | BindingFlags.Instance)
            .GetValue(this);
            bar.SetLogo(Resource.Drawable.icon);
        }
    }
}

Try this one!

Upvotes: 3

FloRup
FloRup

Reputation: 1

I personally haven't used it but I guess you are looking for this:

NavigationPage.SetTitleIcon (this, "image.png");

This will set the title Icon in Xamarin Forms. If you want to change the back button Icon, hamalaiv gave you this link

Upvotes: 0

Related Questions