【问题标题】:Hide title of tabbedPage in Xamarin.Forms Shell在 Xamarin.Forms Shell 中隐藏 tabbedPage 的标题
【发布时间】:2019-07-04 14:53:31
【问题描述】:

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

注意:在这种情况下我使用Flyout,因为我需要一个带有汉堡菜单和标签页的设计,这就是为什么我不只使用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>

TabbedPage Image

MasterPage Image

【问题讨论】:

标签: xamarin.forms xamarin.forms.shell


【解决方案1】:

感谢 GitHub 的 pfedotovsky 用户,在 Xamarin 团队正式解决此问题之前,我找到了替代解决方案,in this article 他解释了它。

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);
        }
    }
}

【讨论】:

    猜你喜欢
    • 2018-09-12
    • 2022-07-10
    • 1970-01-01
    • 1970-01-01
    • 2018-05-05
    • 1970-01-01
    • 2021-06-11
    • 2019-10-16
    • 2021-04-11
    相关资源
    最近更新 更多