You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整Xamarin.Forms中TabbedPage的标签栏选项卡字体大小

问题原因

你之前使用的NavigationPage.TitleView是用来修改ContentPage顶部导航栏的标题样式,并不作用于TabbedPage的Tab标签,因此不会生效。

解决方案

方法1:自定义TabbedPage的ItemTemplate(跨平台通用)

直接在你的TabbedPage代码中添加ItemTemplate配置,自定义Tab标签的字体大小等样式,修改后代码如下:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
            xmlns:local="clr-namespace:Test.ViewModels" 
            xmlns:model="clr-namespace:Test.Models"
            Shell.TabBarBackgroundColor="Transparent"
            x:Class="Test.Views.MainPage">
    <!-- 新增Tab标签自定义样式 -->
    <TabbedPage.ItemTemplate>
        <DataTemplate>
            <Label 
                Text="{Binding Title}" 
                FontSize="12" 
                HorizontalTextAlignment="Center"
                VerticalTextAlignment="Center"/>
        </DataTemplate>
    </TabbedPage.ItemTemplate>

    <ContentPage Title="Delivery">
    </ContentPage>
    <ContentPage Title="Pending">
    </ContentPage>
    <ContentPage Title="Success">
    </ContentPage>
    <ContentPage Title="Failed">
    </ContentPage>
    <ContentPage Title="Summary">
    </ContentPage>
</TabbedPage>

方法2:全局样式修改(适用于Shell场景)

如果你的项目是基于Shell架构,可以直接在App.xaml的资源字典中添加全局样式统一修改Tab标签字体:

<Application.Resources>
    <Style TargetType="Tab">
        <Setter Property="FontSize" Value="12" />
    </Style>
</Application.Resources>

内容的提问来源于stack exchange,提问作者ZachZoe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 01:54:03