我已经在我的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>
当然,除非您想保留textAllCaps
Button
,否则此解决方案有效。