如何自定义在TabbedPage条的大小呢? [XAMARIN.FORMS]

问题描述 投票:0回答:1

我有一个标签页中,我有它已经适应,但我觉得它非常的小,我需要下杆要高

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            x:Class="Mobile.View.Principal"
            xmlns:local="clr-namespace:Mobile.View"
            xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
            BackgroundColor="White"
            BarTextColor="{StaticResource Gris}"
            BarBackgroundColor="white">


    <local:Inicio Title="Inicio" Icon="home_icon.png" HeightRequest="30" WidthRequest="30"/>
    <local:Consultas Title="Consultas" Icon="search_icon.png"/>
    <local:Utilidades Title="Utilidades" Icon="settings_icon.png"/>
    <local:Perfil Title="Perfil" Icon="favorites_icon.png"/>

</TabbedPage>

这是后面的代码:

public partial class Principal : Xamarin.Forms.TabbedPage
{
    public Principal()
    {
        InitializeComponent();
        On<Xamarin.Forms.PlatformConfiguration.Android>().SetToolbarPlacement(ToolbarPlacement.Bottom);
        On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarSelectedItemColor(Color.Black);
        On<Xamarin.Forms.PlatformConfiguration.Android>().SetBarItemColor(Color.LightGray);
        //On<Xamarin.Forms.PlatformConfiguration.Android>().DisableSwipePaging(); //Disable sliding the pages with your finger.
        NavigationPage.SetHasNavigationBar(this, false);  // Hide nav bar
    }

    async void OnPerfilAsync(object sender, EventArgs e)
    {
        await Navigation.PushAsync(new Perfil());
    }
}

这就是应用程序的外观:

enter image description here

怎么会是杆高度属性的名称?

我需要协助!!!

xamarin height tabbed
1个回答
1
投票

在哪个平台,你要改变它呢?你可能需要实现您想要进行此更改的每个平台的custom renderer

对于iOS,您可以在新的普通类文件添加到名为MyTabbedPageRenderer iOS的项目。然后在文件中添加此行的namespace声明之上:

[assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.Forms.TabbedPage), typeof(YourNamespace.MyTabbedPageRenderer))]

其中YourNamespace是命名空间MyTabbedPageRenderer是,即命名空间下方,你有这个属性

现在,请从Xamarin.Forms.Platform.iOS.TabbedRenderer,e.g类继承:

public class MyTabbedPageRenderer : Xamarin.Forms.Platform.iOS.TabbedRenderer

然后下面的覆盖方法添加到类:

public override void ViewWillLayoutSubviews()
    {
        base.ViewWillLayoutSubviews();
        var newHeight = TabBar.Frame.Height + 50;
        CoreGraphics.CGRect tabFrame = TabBar.Frame; //self.TabBar is IBOutlet of your TabBar
        tabFrame.Height = newHeight;
        tabFrame.Y = View.Frame.Size.Height - newHeight;
        TabBar.Frame = tabFrame;
    }

上述将由从默认50个像素增加iOS上的TabBar高度。更改50到你喜欢的任何值。

而针对Android,你其实并不需要进行自定义渲染,因为有一个Android的布局,你可以设置一个TabLayout minHeight。要做到这一点,在你的Android项目打开资源/文件夹布局的Tabbar.axml文件。然后添加一个android:minHeight属性的android.support.design.widget.TabLayout元素:

<android.support.design.widget.TabLayout 
    ...
    android:minHeight="300dp"
    />

这将设置高度为固定300个像素。将它设置为任何你想要的。

或者你可以设置在MainActivity.OnCreate方法的高度。下面是从模板Xam.Forms TabbedPage项目开始。把下面的LoadApplication(new App())调用后:

Android.Support.Design.Widget.TabLayout tabBar = FindViewById<Android.Support.Design.Widget.TabLayout>(Resource.Id.sliding_tabs);
tabBar.SetMinimumHeight(300);

更改Resource.Id对什么android:id是在Tabbar.axml文件TabLayout

© www.soinside.com 2019 - 2024. All rights reserved.