底部选项卡式页面图标仅显示轮廓

时间:2020-08-23 16:26:06

标签: xamarin xamarin.forms xamarin.android

当我将标签放在底部时,图标仅显示轮廓。我只是使用此命令放下指南。

Imagem sem bug Imagem com bug

1 个答案:

答案 0 :(得分:0)

如果要在底部导航视图上使用彩色图标,则必须在Android上为选项卡式页面创建自定义渲染器,然后在此处更改配置:

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