设置标签页的操作栏的文字大小

时间:2017-04-12 09:58:41

标签: xamarin.android android-actionbar tabbedpage

制作第一个标签页代码xaml

<?xml version="1.0" encoding="utf-8" ?>

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="ElronWebtoon_Test.Page1Tab1"
         Title="All">

</ContentPage>

添加标签页代码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="ElronWebtoon_Test.Page1"
             xmlns:pages="clr-namespace:ElronWebtoon_Test;assembly=ElronWebtoon_Test"
             Title="TabbedPage">
  <!--Pages can be added as references or inline-->
  <pages:Page1Tab1/>
    <ContentPage Title="tab1">
        <Grid>

            <StackLayout x:Name="romance">
                <Label Text="Green" HorizontalTextAlignment="Center" HorizontalOptions="FillAndExpand" Margin="5"  />
                <BoxView Color="Green" VerticalOptions="FillAndExpand" />
            </StackLayout>
        </Grid>
    </ContentPage>


    <ContentPage Title="tab2">
        <Grid>               
            <StackLayout>
                <Label Text="Blue" HorizontalTextAlignment="Center" HorizontalOptions="FillAndExpand" Margin="5"  />
                <BoxView Color="Blue" VerticalOptions="FillAndExpand" />
            </StackLayout>
        </Grid>
    </ContentPage>


    <ContentPage Title="tab3">
        <Grid>              
            <StackLayout>
                <Label Text="Pink" HorizontalTextAlignment="Center" HorizontalOptions="FillAndExpand" Margin="5"  />
                <BoxView Color="Pink" VerticalOptions="FillAndExpand" />
            </StackLayout>
        </Grid>
    </ContentPage>

</TabbedPage>

我使用Xamarin Sample制作tabbedPage。

Stackoverflow source

但如果制作多个标签页,

标签页的操作栏标题文字为2行

(例如程序员

- &GT; PROG 夯)

我想要设置操作栏的字体大小,而不是使用自定义渲染器 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

如果您要设置所有标签的字体大小,可以在Android TabLayout.xml中执行此操作

为标签创建样式。

  <style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabTextAppearance">@style/MyCustomTabText</item>
  </style>

  <style name="MyCustomTabText" parent="TextAppearance.AppCompat.Button">
    <item name="android:textSize">10sp</item>
    <item name="android:textColor">@color/primaryDark</item>
  </style>

将样式分配到标签页视图

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:tabTextAppearance="@style/MyCustomTabText"
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Light"
    app:tabTextColor="@color/primaryDark"
    app:tabIndicatorColor="?attr/colorPrimary"
    app:tabIndicatorHeight="0dp"
    app:tabSelectedTextColor="@color/primaryDark"
    app:tabGravity="fill"
    app:tabMode="fixed" />