无法将多色图像添加到 Xamarin Forms 中的 TabbedPage 导航栏

Can't add multi-colour images to TabbedPage navigation bar in Xamarin Forms

因此,当我为 Android 应用程序设计导航栏时,我将其设计成这样: 我在编码时遇到的唯一问题是,当我将每个图标的 .png 图像添加到 MainPage.xaml 上的 XAML 代码中时,图标最终看起来像这样(图标变成黑色没有其他颜色的形状)。

android 是否只能处理 Android 的单色图标? 有什么方法可以禁用此默认功能吗?

我知道 android 样式指南规定您不应为导航栏中的图标使用超过一种颜色,但我需要为此应用程序例外。

如果你想在 Tabbedpage 中使用彩色图标,你应该为 Tabbedpage 创建一个自定义渲染器

using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Views;
using Android.Widget;
using TabbedDemo.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms.Platform.Android.AppCompat;

[assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabbedRenderer))]
namespace TabbedDemo.Droid
{
    public class MyTabbedRenderer : TabbedPageRenderer
    {
        public MyTabbedRenderer(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;
                            }
                        }
                    }
                }
            }
        }
    }
}

这是运行截图。