0

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!

  • I doubt anyone will spot an error in that code. You have two projects. One works, the other doesn’t. You are the only one in a position to discover what is different. It might not be in the code itself. It might be the version of something. Check what Android API is targeted. Check versions of nugets used. OR clone the project that works, and update its nugets and android target API, see if it breaks. Given a working program and a not working program, finding the difference that breaks it - this is a valuable skill to learn. – ToolmakerSteve Jun 06 '22 at 16:16

1 Answers1

1

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.

Alexandar May - MSFT
  • 6,536
  • 1
  • 8
  • 15
  • Thanks for the answer. Setting the background color in the SetAppearance method doesn't throw another error. Unfortunately, I still don't know what to try. Just to be clear here, do I need any other files/classes in my project that might be missing for this to work? Maybe I forgot to copy those to my own project. – User12234327832 Jun 07 '22 at 16:02
  • No,you just need create a base class in a shared projected and then implement the class in each platform.Since it is a Shell project, the `AppShell` is a base class.Have you check this [sample repo](https://github.com/jh-memosoft/Custom-tabbar-icon-in-shell) to see if there's any differences compared with your project? – Alexandar May - MSFT Jun 08 '22 at 02:15
  • Well, I just tried some other possible fixes, and I think I found the (a) solution. I changed the using Android.Support.Design.Widget; to using Google.Android.Material.BottomNavigation;, and now it works. This could also explain why only the old one worked. Thanks everyone! – User12234327832 Jun 08 '22 at 13:38
  • Okay, did that. Thanks again! – User12234327832 Jun 09 '22 at 16:41
  • You are welocme. Don't hesitate to reach out to me if you have any questions. – Alexandar May - MSFT Jun 10 '22 at 00:13