【问题标题】:Android: Setting textAllCaps to false in custom style for TabLayout not workingAndroid:在 TabLayout 的自定义样式中将 textAllCaps 设置为 false 不起作用
【发布时间】:2021-08-19 14:33:02
【问题描述】:

注意:我不想通过在 TabLayout xml 中指定 app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget" 来解决此问题,因为这会覆盖我喜欢的默认选项卡样式。

我尝试了这里提到的另一个解决方案:Android Tablayout Set textAllCaps to False not working,其中包括在我的styles.xml 规范中将textAllCapsandroid:textAllCaps 指定为false。但是,我的选项卡布局继续将 ta 文本显示为大写:

下面是我的styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="standardTabLayout" parent="Widget.Design.TabLayout">
        <item name="textAllCaps">false</item>
        <item name="android:textAllCaps">false</item>
    </style>
</resources>

下面是我的activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        style="@style/standardTabLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Calendar" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Input" />
    </com.google.android.material.tabs.TabLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

    标签: android xml


    【解决方案1】:

    您可以在文本外观中指定您的样式,如下所示:

    app:tabTextAppearance="@style/standardTabLayout"
    

    选项卡布局代码如下所示:

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        style="@style/standardTabLayout"
        android:layout_width="0dp"
        app:tabTextAppearance="@style/standardTabLayout"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
    

    【讨论】:

      猜你喜欢
      • 2015-12-21
      • 2022-07-07
      • 2020-09-04
      • 1970-01-01
      • 2016-06-17
      • 2021-10-17
      • 2014-08-01
      • 2015-07-05
      • 1970-01-01
      相关资源
      最近更新 更多