How to use a custom icon in tab page xamarin forms?

SP Tutorial 21 Reputation points
2021-05-17T10:16:00.38+00:00

I made a tabbed page,and want to use custom tab icon,but the icon is not showing actual image,its changes the overlay.

Here is my tabs
97163-whatsapp-image-2021-05-17-at-153823.jpeg

I want to like this middle icon

97076-whatsapp-image-2021-05-16-at-164211.jpeg

how to do it using tabbed page in xamarin forms

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Answer accepted by question author
  1. Anonymous
    2021-05-17T12:26:59.607+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Please add following custom renderer for tabbedpage.

       using Android.App;  
       using Android.Content;  
       using Android.OS;  
       using Android.Runtime;  
       using Android.Views;  
       using Android.Widget;  
       using Google.Android.Material.BottomNavigation;  
       using System;  
       using System.Collections.Generic;  
       using System.Linq;  
       using System.Text;  
       using TabbedPageWithNavigationPage.Droid;  
       using Xamarin.Forms;  
       using Xamarin.Forms.Platform.Android;  
       using Xamarin.Forms.Platform.Android.AppCompat;  
         
       [assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabbedPageRenderer))]  
       namespace TabbedPageWithNavigationPage.Droid  
       {  
           class MyTabbedPageRenderer : TabbedPageRenderer  
           {  
               public MyTabbedPageRenderer(Context context) : base(context)  
               {  
         
               }  
         
               protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)  
               {  
                   base.OnElementChanged(e);  
         
                   if (e.OldElement == null && e.NewElement != null)  
                   {  
                       for (int i = 0; i <= this.ViewGroup.ChildCount - 1; i++)  
                       {  
                           var childView = this.ViewGroup.GetChildAt(i);  
                           if (childView is ViewGroup viewGroup)  
                           {  
                               for (int j = 0; j <= viewGroup.ChildCount - 1; j++)  
                               {  
                                   var childRelativeLayoutView = viewGroup.GetChildAt(j);  
                                   if (childRelativeLayoutView is BottomNavigationView)  
                                   {  
                                       ((BottomNavigationView)childRelativeLayoutView).ItemIconTintList = null;  
                                   }  
                               }  
                           }  
                       }  
                   }  
               }  
           }  
       }  
    

    Before

    97089-image.png

    After

    97079-image.png

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.