在 Xamarin Android 中使用 TabbedPage.ToolbarPlacement="Bottom" 时如何更改 Tabbar 文本大小?

iam*_*hia 1 xamarin.android xamarin xamarin.forms

我在 Xamarin Forms 中有以下代码:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
            xmlns:local="clr-namespace:XXX;assembly=XXX"
            xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
            BackgroundColor="{DynamicResource BarBackgroundColor}"
            android:TabbedPage.ToolbarPlacement="Bottom"
            android:TabbedPage.BarItemColor="Gray"
            android:TabbedPage.BarSelectedItemColor="{DynamicResource BarSelectedItemColor}"
            android:TabbedPage.IsSwipePagingEnabled="False"
            x:Class="XXX.MainPage">
</TabbedPage>
Run Code Online (Sandbox Code Playgroud)

我想更改Android侧面Tabbar 文本的大小。我尝试创建自己的风格,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyTabLayoutStyle" parent="TextAppearance.Design.Tab">
        <item name="android:textSize">5sp</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

而在我的Tabbar.axml

<?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"
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    app:tabGravity="fill" 
    app:tabMode="fixed"
    app:tabTextAppearance="@style/MyTabLayoutStyle"/>
Run Code Online (Sandbox Code Playgroud)

我有一种感觉这不起作用,因为我正在使用TabbedPage.ToolbarPlacement="Bottom"而不是使用TabLayout,我现在正在使用BottomNavigationView. 因此,上面的问题,如何在使用TabbedPage.ToolbarPlacement="Bottom".

amg*_*vem 6

我花了一个晚上试图解决同样的问题,但我发现的所有解决方案都没有奏效(添加我自己的风格,我真的不想创建自定义渲染器)。最后我翻到了 James Montemagno 的这篇文章:https ://montemagno.com/control-text-size-on-android-bottom-navigation/拯救了我的夜晚!我知道这是一个旧帖子,但如果其他人通过它可能会派上用场。

在您的 Android 项目的 Resource/values 中创建一个文件 dimens.xml(如果它在您的项目中尚不存在)。然后将其添加到您的文件中:

<resources xmlns:tools="http://schemas.android.com/tools">
    <dimen name="design_bottom_navigation_text_size" tools:override="true">12sp</dimen>
    <dimen name="design_bottom_navigation_active_text_size" tools:override="true">12sp</dimen>
</resources>
Run Code Online (Sandbox Code Playgroud)