Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Xamarin.Forms: How to add logo to the navigation bar on Android?

$
0
0

I achieve to add a logo with a custom navigation renderer on iOS. However, I have some troubles with the Android version. Here are my custom renderer codes for Android:

using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using My.app.Droid;

[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationPage))]
namespace My.app.Droid
{
    public class CustomNavigationPage : NavigationRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
        {
            base.OnElementChanged(e);

            var actionBar = ((Activity)Context).ActionBar;
            actionBar.SetIcon(Resource.Drawable.logo);
        }
    }
}

It gives these errors:

1-

Warning CS0618: 'NavigationRenderer.NavigationRenderer()' is obsolete: 'This constructor is obsolete as of version 2.5. Please use NavigationRenderer(Context) instead.' (CS0618)

2-

Error CS0246: The type or namespace name 'Activity' could not be found (are you missing a using directive or an assembly reference?) (CS0246)

I need to have this structure:


Viewing all articles
Browse latest Browse all 204402

Trending Articles



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