android:textAllCaps=“false” not working for TabLayout design Support

后端 未结 13 1414
暗喜
暗喜 2020-11-30 01:27

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

<
相关标签:
13条回答
  • 2020-11-30 02:11

    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>
    
    0 讨论(0)
  • 2020-11-30 02:13

    Just add this to your custom style file

    <item name="android:textStyle">normal</item>
    

    I read all the above solutions and all lead to this.

    0 讨论(0)
  • 2020-11-30 02:15

    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" />
    
    0 讨论(0)
  • 2020-11-30 02:16

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

    <android.support.design.widget.TabLayout
        app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"
    />
    
    0 讨论(0)
  • 2020-11-30 02:16

    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);
        }
    
    0 讨论(0)
  • 2020-11-30 02:17

    Try following method and you can implement all the methods of TextView in TabLayout

    private void setCustomTab() {
    
        ViewGroup vg = (ViewGroup) mTabLayout.getChildAt(0);
        int tabsCount = vg.getChildCount();
        for (int j = 0; j < tabsCount; j++) {
            ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
            int tabChildsCount = vgTab.getChildCount();
            for (int i = 0; i < tabChildsCount; i++) {
                View tabViewChild = vgTab.getChildAt(i);
                if (tabViewChild instanceof TextView) {
                    ((TextView) tabViewChild).setTypeface(ResourcesCompat.getFont(this,R.font.montserrat_medium));
                    ((TextView) tabViewChild).setAllCaps(false);
                }
            }
        }
    }
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题