xamarin.android - 为选项卡式页面选项卡文本设置自定义字体大小

标签 xamarin.android xamarin.forms

我正在尝试减小 Tab 文本大小,因为它会因长文本而被截断。我尝试了以下解决方案,但它似乎不起作用。

 <style name="MainTheme" parent="MainTheme.Base">
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#2196F3</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#1976D2</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#FF4081</item>
    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>

    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>

    <item name="android:actionBarTabTextStyle">@style/CustomTab</item>
    <item name="actionBarTabTextStyle">@style/CustomTab</item>
  </style>

  <style name="CustomTab"
         parent="@style/Widget.AppCompat.Light.ActionBar.TabText">
    <item name="android:textSize">5sp</item>
  </style>

谁能帮帮我?

最佳答案

在 styles.xml 中

  <style name="MyTabLayout" parent="Base.Widget.Design.TabLayout">
    <item name="tabTextAppearance">@style/MyTabTextAppearance</item>
  </style>

  <style name="MyTabTextAppearance" parent="TextAppearance.AppCompat.Button">
    <item name="android:textSize">5sp</item>
  </style>

在 Tabbar.axml 中

<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/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:tabIndicatorColor="@android:color/white"
    style="@style/MyTabLayout"
    app:tabGravity="fill"
    app:tabMode="fixed" />

enter image description here

关于xamarin.android - 为选项卡式页面选项卡文本设置自定义字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45643801/

相关文章:

ios - Appcenter Push iOS - 控制何时请求推送权限

c# - Xamarin.Android 点击手势和长按手势不能一起工作

xamarin - 如何在Xamarin Carousel中将所有项目模板数据设置到单个 View 中

c# - Mono.Data.Sqlite.SqliteConnection.SetConfig 抛出一个 Library used incorrectly 异常

android - 如何在 C# 中将 Android.Net.Uri 转换为字节数组

xamarin - 反序列化 Google-services.json 文件时出错

c# - 如何播放即使您在 Xamarin Forms 中浏览页面也能继续播放的音频文件?

xamarin - 如何使用 Xamarin 表单(MAUI)中的 dll/nuget 从核心项目访问 MaterialIconsFont.ttf?

c# - 如何从 Xamarin Forms for Android 的按钮 View 中删除额外的填充?

c# - 如何在 Xamarin.Android 的 try catch block 中捕获所有异常