hagnr hagnr - 10 months ago 252
C# Question

Change icon on Navigation bar - Xamarin.Forms Android

How can I set different icons in Xamarin.Forms - android.

One for the application, play store, user screen and other for the navigation page.

I updated Project.Droid/MainActivity.cs file:

[Activity(Label = "MyAppName", Icon = "MyIconName", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

But this way change two icons!!

Other way that I did, I updated ProjectForms/App.cs:

Current.Resources = new ResourceDictionary();
Current.Resources.Add("UlycesColor", Color.FromRgb(121, 248, 81));
var navigationStyle = new Style(typeof(NavigationPage));
var barTextColorSetter = new Setter { Property = NavigationPage.BarTextColorProperty, Value = Color.Black };
var barBackgroundColorSetter = new Setter { Property = NavigationPage.BarBackgroundColorProperty, Value = Color.White };
var barIcon = new Setter { Property = NavigationPage.IconProperty, Value = "newIcon.png" };


But doesn't work!!

Any idea???


You could do it with custom renderer:

[assembly:ExportRenderer (typeof(NavigationPage), typeof(NavigationPageRenderer))]
namespace SuperForms.Samples.Droid
    public class NavigationPageRenderer : NavigationRenderer
        protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)

            var actionBar = ((Activity)Context).ActionBar;

Add icon to Resources/drawable folder:

enter image description here

How it will looks:

enter image description here