Xamarin选项卡式页面选项卡没有填充空间吗?

时间:2019-09-24 09:03:50

标签: c# android xamarin xamarin.forms

我的Xamarin.Forms应用程序中有一个TabbedPage,当部署到Android平板电脑时,它拒绝填充可用空间。在Pixel模拟器上进行测试可以正确显示导航选项卡-它们具有图标,标题,并且可以填充可用的屏幕空间;而在横向模式的平板电脑上,它们保留为微小的方形标签。

我正在用C#生成选项卡,因为我需要具有特定构造函数的页面。我在C#或通常认为设置为FillAndExpand的TabbedPage的.xaml中都找不到任何Horizo​​ntalOptions属性。我该怎么做?

//TabbedPage (HomePage) generation code in C#
//There is no additional styling in the .xaml file.

public HomePage(Type1 type1, Type2 type2)
        {
            InitializeComponent();

            this.type1 = type1;
            this.type2 = type2;
            var page1 = new FirstPage(type1, type2);
            page1.IconImageSource = "ic_one.png";
            page1.Title = "Page 1";
            var page2 = new SecondPage(type1, type2);
            page2.IconImageSource = "ic_two.png";
            page2.Title = "Page 2";
            var page3 = new ThirdPage(type1, type2);
            page3.IconImageSource = "ic_three.png";
            page3.Title = "Page 3";

            Children.Add(page1);
            Children.Add(page2);
            Children.Add(page3);
        }

 protected override void OnAppearing()
        {
            NavigationPage.SetHasNavigationBar(this, false);
            NavigationPage.SetHasBackButton(this, true);
            base.OnAppearing();
        }

1 个答案:

答案 0 :(得分:0)

您可以从nuget安装软件包 Naxam.BottomTabbedPage

将根元素更改为BottomTabbedPage(也更改后面的代码)

<naxam:BottomTabbedPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:Demo"
    xmlns:naxam="clr-namespace:Naxam.Controls.Forms;assembly=Naxam.Controls.Forms"
    x:Class="xxx.MainPage">
    <local:Page1 />
    <local:Page2 />
    <local:Page3 />
    <local:Page4 />
    <local:Page5 />
</naxam:BottomTabbedPage>

更改活动班级的颜色/高度

BottomTabbedRenderer.BackgroundColor = new Android.Graphics.Color(23, 31, 50);
BottomTabbedRenderer.FontSize = 10;
BottomTabbedRenderer.IconSize = 20;
BottomTabbedRenderer.ItemTextColor = stateList;
BottomTabbedRenderer.ItemIconTintList = stateList;
BottomTabbedRenderer.Typeface = Typeface.CreateFromAsset(this.Assets, "HiraginoKakugoProNW3.otf");
BottomTabbedRenderer.ItemBackgroundResource = Resource.Drawable.bnv_selector;
BottomTabbedRenderer.ItemSpacing = 8;
BottomTabbedRenderer.ItemPadding = new Xamarin.Forms.Thickness(8);
BottomTabbedRenderer.BottomBarHeight = 80;
BottomTabbedRenderer.ItemAlign = BottomTabbedRenderer.ItemAlignFlags.Center;

有关更多详细信息,请检查here