android:textAllCaps=“false” not working for TabLay

2019-01-07 18:55发布

I have set android:textAllCaps="false" in my android.support.design.widget.TabLayout thought it is showing the Tab Title in All caps only.

How can I remove all caps?

11条回答
Ridiculous、
2楼-- · 2019-01-07 19:34

UPDATE FOR DESIGN LIBRARY 23.2.0+

The original answer doesn't work with design library 23.2.0 or later. Thanks for @fahmad6 pointed out in comment, in case someone missed that comment, I'll put it here. You need to set both textAllCaps and android:textAllCaps to false to disable all capitalize setting.

<style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
      <item name="textAllCaps">false</item>
      <item name="android:textAllCaps">false</item>
</style>

ORIGINAL ANSWER

By default, tabs are created by TabLayout sets the textAllCaps property to be true, you have to define a style making this flag false.

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
      <item name="tabTextAppearance">@style/MyCustomTextAppearance</item>
</style>

<style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
      <item name="textAllCaps">false</item>
</style>
查看更多
戒情不戒烟
3楼-- · 2019-01-07 19:34

Here is simple solution....Enjoy

 for (int tabIndex = 0; tabIndex <tabLayout.getTabCount() ; tabIndex++) {
        TextView tabTextView = (TextView)(((LinearLayout)((LinearLayout)tabLayout.getChildAt(0)).getChildAt(tabIndex)).getChildAt(1));
        tabTextView.setAllCaps(false);
    }
查看更多
相关推荐>>
4楼-- · 2019-01-07 19:35

use this attribute app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget" It will work.

  <android.support.design.widget.TabLayout
    android:id="@+id/tablayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    app:tabGravity="fill"
    app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
    app:tabIndicatorColor="@color/colorPrimary"
    app:tabMode="fixed"
    app:tabPaddingStart="0dp" />
查看更多
对你真心纯属浪费
5楼-- · 2019-01-07 19:39

https://stackoverflow.com/a/34678235/1025379

<android.support.design.widget.TabLayout
    app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
/>
查看更多
Summer. ? 凉城
6楼-- · 2019-01-07 19:41

In my case two variants work:

1) By Bogdan (susemi99):

<android.support.design.widget.TabLayout
    app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
/>

2) By Paresh Mayani. I wanted to have android:textAllCaps="false" and android:textSize="12sp" simultaneously, so his old method works:

in styles.xml:

<style name="TabLayout" parent="Widget.Design.TabLayout">
    <item name="android:textSize">12sp</item>
    <item name="tabIndicatorColor">@color/color_blue</item>
    <item name="tabSelectedTextColor">@color/color_blue</item>
    <item name="tabTextColor">@color/black</item>
    <item name="tabTextAppearance">@style/TabLayoutTextAppearance</item>
</style>

<style name="TabLayoutTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="textAllCaps">false</item>
    <item name="android:textAllCaps">false</item>
</style>

Apply this style in layout:

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/TabLayout"
    />
查看更多
女痞
7楼-- · 2019-01-07 19:42

Change: <item name="android:textAllCaps">false</item>

With: <item name="textAllCaps">false</item>

查看更多
登录 后发表回答