在 Xamarin.Forms Shell 中隐藏 tabbedPage 的标题
Hide title of tabbedPage in Xamarin.Forms Shell
我正在使用 shell that was released with Xamarin.Forms 4.0 and now I was migrating a tabbedPage that had an effect 将项目重构为新导航
应用于从 tabbedPage 中隐藏 children 的标题,使图标仅可见,使用 Shell 页面不再需要从 TabbedPage 继承,如果不是 class Shell 允许您实现 tabbedPage、masterPage ... 问题是现在我不知道如何应用我以前使用的 effect 因为我无法引用 tabbedPage。
注意:在这种情况下我使用Flyout since I need a design with a hamburger menu and also tabbedPage, that's why I do not use only the 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
感谢 pfedotovsky user of GitHub I have found an alternative solution until the Xamarin team officially resolves this, 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);
}
}
}
我正在使用 shell that was released with Xamarin.Forms 4.0 and now I was migrating a tabbedPage that had an effect 将项目重构为新导航 应用于从 tabbedPage 中隐藏 children 的标题,使图标仅可见,使用 Shell 页面不再需要从 TabbedPage 继承,如果不是 class Shell 允许您实现 tabbedPage、masterPage ... 问题是现在我不知道如何应用我以前使用的 effect 因为我无法引用 tabbedPage。
注意:在这种情况下我使用Flyout since I need a design with a hamburger menu and also tabbedPage, that's why I do not use only the 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
感谢 pfedotovsky user of GitHub I have found an alternative solution until the Xamarin team officially resolves this, 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);
}
}
}