如何调整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
相关产品推荐
相关产品推荐

