0

我正在开发一个复杂的应用程序,并利用 Xamarin.Forms.Shell 的优势进行布局和导航。现在有一些烦人的事情我还没有找到解决方案。

应用程序本身及其内容是德语。有没有一种干净的方法可以将硬编码的“更多”选项卡文本更改为德语翻译(“Mehr”)?

尽管更多选项卡非常好,但它不适合我对应用程序布局的需求。按下它时,我想显示一个视图,其中包含的不仅仅是带有标签的图标列表。我想将视图分成带有标题的部分,在这些标题中我想显示该部分的连贯页面。最简单的方法是用单页选项卡替换多页“更多选项卡”,并按照描述设计页面,但我喜欢更多选项卡的菜单外观,如果可能的话,我想保留它。

提前感谢您的任何帮助或建议。

4

1 回答 1

1

您可以自定义ShellRendererText来修改更多选项卡。

AndroidCustomShellRenderer.cs中的解决方案:

public class CustomShellRenderer : ShellRenderer
{
    public CustomShellRenderer(Context context) : base(context)
    {

    }

    protected override IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
    {
        return new MarginedTabBarAppearance();
    }
}

public class MarginedTabBarAppearance : IShellBottomNavViewAppearanceTracker
{
    public void Dispose()
    {
    }

    public void ResetAppearance(BottomNavigationView bottomView)
    {
    }

    public void SetAppearance(BottomNavigationView bottomView, ShellAppearance appearance)
    {
    }

    public void SetAppearance(BottomNavigationView bottomView, IShellAppearanceElement appearance)
    {
        if(null != bottomView.Menu.GetItem(4))
        {
            IMenuItem menuItem = bottomView.Menu.GetItem(4);
            menuItem.SetTitle(Resource.String.More);
        }
    }
}

strings.xml:_

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <string name="More">Mehr</string>
</resources>

效果:

在此处输入图像描述

iOSCustomShellRenderer.cs中的解决方案:

public class CustomShellRenderer: ShellRenderer
{
    protected override IShellTabBarAppearanceTracker CreateTabBarAppearanceTracker()
    {
        return new TabBarAppearance();
    }
}

public class TabBarAppearance : IShellTabBarAppearanceTracker
{
    public void Dispose()
    {
    }

    public void ResetAppearance(UITabBarController controller)
    {
    }

    public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
    {
    }

    public void UpdateLayout(UITabBarController controller)
    {
        UITabBar tb = controller.MoreNavigationController.TabBarController.TabBar;
        if (tb.Subviews.Length > 4)
        {
            UIView tbb = tb.Subviews[4];
            UILabel label = (UILabel)tbb.Subviews[1];
            label.Text = "Mehr";
        }
    }
}

效果:

在此处输入图像描述

以上代码基于这个官方示例项目(Xamarin.Forms - Xaminals)

于 2021-02-03T09:57:03.990 回答