android:textAllCaps=“false”不适用于 com.google.android.material.tabs.TabLayout
android:textAllCaps=“false” not working for com.google.android.material.tabs.TabLayout
我在我的 com.google.android.material.tabs.TabItem 中设置了 android:textAllCaps="false" 以为它只显示全部大写的标签标题。
如何删除所有大写字母?
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.google.android.material.tabs.TabItem
android:id="@+id/TabWeekly"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/Weekly"
android:textAllCaps="false"
android:theme="@style/CustomTextAppearanceTab" />
<com.google.android.material.tabs.TabItem
android:id="@+id/TabMonthly"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/Monthly"
android:textAllCaps="false"
android:theme="@style/CustomTextAppearanceTab" />
</com.google.android.material.tabs.TabLayout>
我还给它设置了样式
<style name="CustomTextAppearanceTab" parent="TextAppearance.Design.Tab">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
但它不起作用
自定义样式
<style name="customTabLayout" parent="Widget.Design.TabLayout">
<item name="tabTextAppearance">@style/TabTextAppearance</item>
</style>
<style name="TabTextAppearance" parent="@android:style/TextAppearance.Widget.TabWidget">
<item name="android:textAllCaps">false</item>
</style>
选项卡布局xml代码
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab"
style="@style/customTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
您可以利用 TabLayout
使用与 Button
相同的文本外观这一事实。
首先,添加新的文字外观:
<style name="TextAppearance.MyApplication.Button" parent="TextAppearance.MaterialComponents.Button">
<item name="android:textAllCaps">false</item>
</style>
其次,在应用主题中作为textAppearanceButton
应用:
<item name="textAppearanceButton">@style/TextAppearance.MyApplication.Button</item>
当然,除非您想为 Button
保留 textAllCaps
。
,否则此解决方案有效
我在我的 com.google.android.material.tabs.TabItem 中设置了 android:textAllCaps="false" 以为它只显示全部大写的标签标题。
如何删除所有大写字母?
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.google.android.material.tabs.TabItem
android:id="@+id/TabWeekly"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/Weekly"
android:textAllCaps="false"
android:theme="@style/CustomTextAppearanceTab" />
<com.google.android.material.tabs.TabItem
android:id="@+id/TabMonthly"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/Monthly"
android:textAllCaps="false"
android:theme="@style/CustomTextAppearanceTab" />
</com.google.android.material.tabs.TabLayout>
我还给它设置了样式
<style name="CustomTextAppearanceTab" parent="TextAppearance.Design.Tab">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
但它不起作用
自定义样式
<style name="customTabLayout" parent="Widget.Design.TabLayout">
<item name="tabTextAppearance">@style/TabTextAppearance</item>
</style>
<style name="TabTextAppearance" parent="@android:style/TextAppearance.Widget.TabWidget">
<item name="android:textAllCaps">false</item>
</style>
选项卡布局xml代码
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab"
style="@style/customTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
您可以利用 TabLayout
使用与 Button
相同的文本外观这一事实。
首先,添加新的文字外观:
<style name="TextAppearance.MyApplication.Button" parent="TextAppearance.MaterialComponents.Button">
<item name="android:textAllCaps">false</item>
</style>
其次,在应用主题中作为textAppearanceButton
应用:
<item name="textAppearanceButton">@style/TextAppearance.MyApplication.Button</item>
当然,除非您想为 Button
保留 textAllCaps
。