0

我正在将一个项目重构为使用 Xamarin.Forms 4.0 发布的带有shell的新导航,现在我正在迁移一个 tabbedPage,它的效果是从 tabbedPage 中隐藏子项的标题,使图标仅可见,使用 Shell如果不是自己的Shell类允许您实现tabbedPage,masterPage,则不再需要页面从TabbedPage继承...问题是现在我不知道如何应用以前使用的效果,因为我不能参考tabbedPage。

注意:在这种情况下,我使用Flyout,因为我需要一个带有汉堡菜单和 tabbedPage 的设计,这就是我不只使用TabBar的原因。

<FlyoutItem Route="home"
            Title="TEST"
            Icon="home_icon"
            FlyoutDisplayOptions="AsMultipleItems">
    <ShellContent Route="bottomtab1"
                  Title="TEST1"
                  Icon="target_icon"
                  ContentTemplate="{DataTemplate views:x}" />
    <ShellContent Route="bottomtab2"
                  Title="TEST2"
                  Icon="user_login"
                  ContentTemplate="{DataTemplate views:y}" />
</FlyoutItem>

标签页图像

母版页图像

4

1 回答 1

0

感谢 GitHub 的pfedotovsky用户,在 Xamarin 团队正式解决此问题之前,我找到了替代解决方案,他在本文中对此进行了解释。

Android 有一个带有自定义渲染器的解决方法。关键是设置

_bottomView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityAuto; 或 _bottomView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityUnlabeled;

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

namespace App.Droid
{
    public class AndroidShellItemRenderer : ShellItemRenderer
    {
        BottomNavigationView _bottomView;

        public AndroidShellItemRenderer(IShellContext shellContext) : base(shellContext)
        {
        }

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var outerlayout = base.OnCreateView(inflater, container, savedInstanceState);

            _bottomView = outerlayout.FindViewById<BottomNavigationView>(Resource.Id.bottomtab_tabbar);
            _bottomView.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityAuto;

            return outerlayout;
        }
    }
}

要使用此渲染器,您还需要创建自定义 ShellRenderer:

using System;
using Android.Content;
using Conference.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(Shell), typeof(AndroidShellRenderer))]
namespace App.Droid
{
    public class AndroidShellRenderer : ShellRenderer
    {
        public AndroidShellRenderer(Context context)
            : base(context)
        {
        }

        protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
        {
            return new AndroidShellItemRenderer(this);
        }
    }
}
于 2019-10-26T19:57:07.420 回答