在使用3个以上的标签后,TabbedPage并不总是显示标签的标签

时间:2019-12-19 09:33:16

标签: android xamarin shift tabbedpage

我在导航时得到了这个

     <TabbedPage ....

       <TabbedPage.Children>
            <NavigationPage Title=" MY_TITLE_1 ">
                <NavigationPage.Icon>
                    <OnPlatform x:TypeArguments="FileImageSource">
                        <On Platform="Android" Value="icon1.png" />
                        <On Platform="iOS" Value="icon1.png" />
                    </OnPlatform>
                </NavigationPage.Icon>
            </NavigationPage>
            <NavigationPage Title=" MY_TITLE_2 ">
   ....
     </TabbedPage>

问题是,当我放置4或5个选项卡时,我的文本被隐藏了,我需要单击该选项卡才能看到该文本(换句话说,我只能看到被单击的选项卡的文本)

在iOS中,文本始终可见。 还有什么办法可以在Android中实现吗?

1 个答案:

答案 0 :(得分:-1)

已解决:这篇文章对我有用。解决方案是关闭换档。

https://montemagno.com/xamarin-forms-fully-customize-bottom-tabs-on-android-turn-off-shifting/

总而言之,我更新了

  

Xamarin.Android.Support.Core.Utils,   Xamarin.Android.Support.CustomTabs,   Xamarin.Android.Support.Design,   Xamarin.Android.Support.v4,   Xamarin.Android.Support.v7.AppCombat,   Xamarin.Android.Support.7.cardView,   Xamarin.Android.Support.v7.MediaRouter

我在Android解决方案中创建了此文件:

  using Android.Support.Design.BottomNavigation;
using Android.Support.Design.Widget;
using Android.Views;
using App16.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly:ResolutionGroupName ("MyCompany")]
[assembly:ExportEffect (typeof(NoShiftEffect), "NoShiftEffect")]
namespace App16.Droid
{
    public class NoShiftEffect : PlatformEffect
    {
        protected override void OnAttached ()
        {
            if (!(Container.GetChildAt(0) is ViewGroup layout))
                return;

            if (!(layout.GetChildAt(1) is BottomNavigationView bottomNavigationView))
                return;

            // This is what we set to adjust if the shifting happens
            bottomNavigationView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityLabeled;
        }

        protected override void OnDetached ()
        {
        }
    }
}

在共享解决方案中:

    using Xamarin.Forms;

namespace App16
{
    public class NoShiftEffect : RoutingEffect
    {
        public NoShiftEffect() : base("MyCompany.NoShiftEffect")
        {
        }
    }
}

这在我的XAML中:

<TabbedPage.Effects>
    <local:NoShiftEffect />
</TabbedPage.Effects>