Home > front end >  Xamarin: 'CustomBottomNavAppearance' does not implement interface member 'IShellBotto
Xamarin: 'CustomBottomNavAppearance' does not implement interface member 'IShellBotto

Time:06-10

I've recently tried to customize the tabbar using a custom ShellRenderer in my app using Xamarin and Visual Studio 2019. I've found this question where someone does exactly what I need and the question has an answer which explains it in great detail.

Now, my problem is that when trying to build the app, I get the following error:

'CustomBottomNavAppearance' does not implement interface member 'IShellBottomNavViewAppearanceTracker.SetAppearance(BottomNavigationView,IShellAppearanceElement)' (Errorcode CS0535, line 32)

Now, the sample project that the user in the other question provides works perfectly on my machine, yet implementing it in my project doesn't work, although they are practiacally identical.

I expect this to be very obvious for an advanced user, so sorry about that, I'm still learning and would like to just implement this feature right now, even if my skills might not allow me to do that.

Thanks in advance for any replies!

This is my 'MyShellRenderer.cs' class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Google.Android.Material.BottomNavigation;
using MyProject;
using MyProject.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(AppShell), typeof(MyShellRenderer))]
namespace MyProject.Droid
{
    public class MyShellRenderer : ShellRenderer
    {
        public MyShellRenderer(Context context) : base(context)
        {
        }

        protected override IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
        {
            return new CustomBottomNavAppearance();
        }
    }

    public class CustomBottomNavAppearance : IShellBottomNavViewAppearanceTracker
    {
        public void Dispose()
        {

        }

        public void ResetAppearance(BottomNavigationView bottomView)
        {

        }

        public void SetAppearance(BottomNavigationView bottomView, ShellAppearance appearance)
        {
            IMenu myMenu = bottomView.Menu;

            IMenuItem myItemOne = myMenu.GetItem(0);

            if (myItemOne.IsChecked)
            {
                myItemOne.SetIcon(Resource.Drawable.icon_about);
            }
            else
            {
                myItemOne.SetIcon(Resource.Drawable.icon_feed);
            }
        }
    }
}

Edit: I've just found out that the issue actually only exists with the Android version (well, the iOS version at least doesn't throw the error).

Update: I have been able to fix the issue by using "using Google.Android.Material.BottomNavigation;" "using Android.Support.Design.Widget;". My guess it that the old one is now deprecated and only works with the 4.x.x releases, not my 5.x.x release. Thanks everyone!

CodePudding user response:

Per this docs,The error does not implement interface member Errorcode CS0535 means A class must implement all members of interfaces from which it derives or else be declared abstract.So the issue must be that the method SetAppearance has not been correctly implemented.When I Remove or Comment the SetAppearance method, the error appears.

The solution is that using using Google.Android.Material.BottomNavigation instead of using Android.Support.Design.Widget.

  • Related