Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在选项卡页面中自定义栏的大小?[XAMARIN.表格]_C#_Xamarin_Height_Tabbed - Fatal编程技术网

C# 如何在选项卡页面中自定义栏的大小?[XAMARIN.表格]

C# 如何在选项卡页面中自定义栏的大小?[XAMARIN.表格],c#,xamarin,height,tabbed,C#,Xamarin,Height,Tabbed,我有一个标签页,我已经容纳了它,但我觉得它非常小,我需要较低的酒吧更高 <?xml version="1.0" encoding="utf-8" ?> <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

我有一个标签页,我已经容纳了它,但我觉得它非常小,我需要较低的酒吧更高

<?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());
    }
}
public分部类主体:Xamarin.Forms.TabbedPage
{
公共负责人()
{
初始化组件();
On().SetToolbarPlacement(ToolbarPlacement.Bottom);
On().SetBarSelectedItemColor(Color.Black);
On().SetBarItemColor(Color.LightGray);
//On().DisableSwipePaging();//禁用用手指滑动页面。
NavigationPage.SetHasNavigationBar(this,false);//隐藏导航栏
}
异步void OnPerfilAsync(对象发送方,事件参数e)
{
等待Navigation.PushAsync(新Perfil());
}
}
这就是应用程序的外观:

条形高度属性的名称如何?


我需要一些帮助

您想在哪个平台上更改它?您可能需要为要进行此更改的每个平台实现一个

对于iOS,您可以向名为
MyTabbedPageRenderer
的iOS项目添加新的常规类文件。然后在文件中,在
名称空间
声明上方添加此行:

[assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.Forms.TabbedPage), typeof(YourNamespace.MyTabbedPageRenderer))]
其中,
YourNamespace
MyTabbedPageRenderer
所在的命名空间,即位于该属性下方的命名空间

现在让类继承自
Xamarin.Forms.Platform.iOS.TabbedRenderer
,例如:

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;
    }
上述操作将使iOS上的选项卡栏高度从默认值增加50像素。将
50
更改为您喜欢的任何值

对于Android,实际上不需要定制渲染器,因为有一个Android布局,您可以为TabLayout设置
minHeight
。为此,请在Android项目的resources/layout文件夹中打开Tabbar.axml文件。然后在
android.support.design.widget.TabLayout
元素中添加一个
android:minHeight
属性:

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

Resource.Id
更改为Tabbar.axml文件中
TabLayout
android:Id
所对应的任何内容

您希望在哪个平台上更改它?您可能需要为要进行此更改的每个平台实现一个

对于iOS,您可以向名为
MyTabbedPageRenderer
的iOS项目添加新的常规类文件。然后在文件中,在
名称空间
声明上方添加此行:

[assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.Forms.TabbedPage), typeof(YourNamespace.MyTabbedPageRenderer))]
其中,
YourNamespace
MyTabbedPageRenderer
所在的命名空间,即位于该属性下方的命名空间

现在让类继承自
Xamarin.Forms.Platform.iOS.TabbedRenderer
,例如:

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;
    }
上述操作将使iOS上的选项卡栏高度从默认值增加50像素。将
50
更改为您喜欢的任何值

对于Android,实际上不需要定制渲染器,因为有一个Android布局,您可以为TabLayout设置
minHeight
。为此,请在Android项目的resources/layout文件夹中打开Tabbar.axml文件。然后在
android.support.design.widget.TabLayout
元素中添加一个
android:minHeight
属性:

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

Resource.Id
更改为Tabbar.axml文件中
TabLayout
android:Id
的任何内容更新:不再有“resources/layout”文件夹。这对于android2021更新不再有效:不再有“资源/布局”文件夹。这对android已经不起作用了