【问题标题】:How to Decrease Height of Navigation bar in xamarin forms如何降低 xamarin 表单中导航栏的高度
【发布时间】:2017-07-19 12:37:14
【问题描述】:

我使用 MasterDetail 页面作为我的应用程序的主页。这里 TabbedPage 是我的详细信息页面,其中包含各种 ContentPage 作为 TabbedPage 的子项。我已将详细信息设置为 Detail = NavigationPage(tabbedpage);它对 IOS 非常有用,但在 android 中它在 NavigationBar 标题和 Tabbed Name 中占用更多空间,我不能同时忽略两者,我的问题是如何降低导航页面标题栏的高度。 请查看附件图片以供参考。

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    例如,您需要设置特定的填充平台。

    <OnPlatform x:TypeArguments="FontAttributes" x:Key="fontAttributes">
            <OnPlatform.iOS>Bold</OnPlatform.iOS>
            <OnPlatform.Android>Italic</OnPlatform.Android>
    </OnPlatform>
    

    【讨论】:

      【解决方案2】:

      您需要使用自定义渲染器实现 CustomNavigationPage。参考这个-https://xamgirl.com/transparent-navigation-bar-in-xamarin-forms/

      <?xml version="1.0" encoding="utf-8" ?>
      <NavigationPage 
          xmlns="http://xamarin.com/schemas/2014/forms"
          xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
          x:Class="TransparentNavBarXForms.CustomNavigationPage"
          BarTextColor="White">
          <NavigationPage.BarBackgroundColor>
              <OnPlatform x:TypeArguments="Color">
                  <On Platform="Android, iOS" Value="Transparent" />
              </OnPlatform>
          </NavigationPage.BarBackgroundColor>
      </NavigationPage>
      
      public partial class CustomNavigationPage : NavigationPage
      {
          public CustomNavigationPage() : base()
          {
              InitializeComponent();
          }
      
          public CustomNavigationPage(Page root) : base(root)
          {
              InitializeComponent();
          }
      
          public bool IgnoreLayoutChange { get; set; } = false;
      
          protected override void OnSizeAllocated(double width, double height)
          {
              if (!IgnoreLayoutChange)
                  base.OnSizeAllocated(width, height);
          }
      }
      
      public class CustomNavigationPageRenderer : NavigationPageRenderer
      {
          public CustomNavigationPageRenderer(Context context) : base(context)
          {
      
          }
      
          IPageController PageController => Element as IPageController;
          CustomNavigationPage CustomNavigationPage => Element as CustomNavigationPage;
      
          protected override void OnLayout(bool changed, int l, int t, int r, int b)
          {
              CustomNavigationPage.IgnoreLayoutChange = true;
              base.OnLayout(changed, l, t, r, b);
              CustomNavigationPage.IgnoreLayoutChange = false;
      
              int containerHeight = b - t;
      
              PageController.ContainerArea = new Rectangle(0, 0, Context.FromPixels(r - l), Context.FromPixels(containerHeight));
      
              for (var i = 0; i < ChildCount; i++)
              {
                  AView child = GetChildAt(i);
      
                  if (child is Android.Support.V7.Widget.Toolbar)
                  {
                      continue;
                  }
      
                  child.Layout(0, 0, r, b);
              }
          }
      }
      
      public partial class App : Application
      {
          public App()
          {
              InitializeComponent();
      
              MainPage = new CustomNavigationPage(new MainPage());
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-03
        • 2017-08-23
        • 1970-01-01
        • 2013-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多