TabbedPage 的自定义渲染器隐藏了 Tabbar

Custom renderer for TabbedPage hides Tabbar

我目前正在尝试为我的 TabbedPage 使用 自定义渲染器

我实际上想使用 renderer 来更改选项卡的字体。不幸的是,当我使用 renderer 时,Tabbar 不可见。如果没有 renderer,则会显示 Tabbar

我是不是忘记了什么?

我的页面:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:d="http://xamarin.com/schemas/2014/forms/design"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        xmlns:views="clr-namespace:***.Views"
        x:Class="***.Views.MainPage"
        xmlns:utils="clr-namespace:***.Utils"
        BarBackgroundColor="Black" BarTextColor="White"
        xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
        android:TabbedPage.ToolbarPlacement="Bottom"
        android:TabbedPage.BarTextColor="White"
        android:TabbedPage.BarItemColor="Gray"
        android:TabbedPage.BarSelectedItemColor="White"
        android:TabbedPage.IsSwipePagingEnabled="False"
        CurrentPageChanged="changeTab"
        x:Name="mainTabbedView">

<TabbedPage.Children>
    <NavigationPage Title="1" HeightRequest="20">
        <NavigationPage.Icon>
            <OnPlatform x:TypeArguments="FileImageSource" >
                <On Platform="iOS" Value="pic1"/>
                <On Platform="Android" Value="pic1"/>
            </OnPlatform>
        </NavigationPage.Icon>
        <x:Arguments>
            <views:NewPage />
        </x:Arguments>
    </NavigationPage>

    <NavigationPage Title="2">
        <NavigationPage.Icon>
            <OnPlatform x:TypeArguments="FileImageSource">
                <On Platform="iOS" Value="pic2"/>
                <On Platform="Android" Value="pic2"/>
            </OnPlatform>
        </NavigationPage.Icon>
        <x:Arguments>
            <views:OtherPage />
        </x:Arguments>
    </NavigationPage>

    <NavigationPage Title="3">
        <NavigationPage.Icon>
            <OnPlatform x:TypeArguments="FileImageSource">
                <On Platform="iOS" Value="pic3"/>
                <On Platform="Android" Value="pic3"/>
            </OnPlatform>
        </NavigationPage.Icon>
        <x:Arguments>
            <views:LastPage />
        </x:Arguments>
    </NavigationPage>
</TabbedPage.Children>

渲染器:

using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using ***.Droid;
using Android.Content;


[assembly: ExportRenderer(typeof(TabbedPage), typeof(CustomTabbedPageRenderer))]

namespace ***.Droid
{
    class CustomTabbedPageRenderer : TabbedRenderer
    {
        public CustomTabbedPageRenderer(Context context) : base(context)
        {
        }
    }
}

我希望你最终解决了你的问题,如果没有:

解决方案

在您的渲染器中,在 Android 项目中,您必须继承 TabbedPageRenderer 而不是 TabbedRenderer,如下所示

...
public class CustomTabbedPageRenderer : TabbedPageRenderer
{
  public CustomTabbedPageRenderer(Context context) : base(context)
  {
  }
}
...

备注

可以找到类似的问题