7

I want to put tabs text(max 8 chars) in single line

enter image description here

I added a custom style to TabLayout element

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item>
</style>
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="android:maxLines">1</item>
    <item name="android:singleLine">true</item>
</style>

Still it does not work out. I also tried

 <android.support.design.widget.TabLayout
  app:tabTextAppearance="@style/MyCustomTabTextAppearance"
  ..
  ..
  />
azizbekian
  • 60,783
  • 13
  • 169
  • 249
Harsh
  • 644
  • 3
  • 14
  • 27

3 Answers3

18

Just add app:tabMode="scrollable" to TabLayout;

<android.support.design.widget.TabLayout 
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_tabs" 
android:layout_width="match_parent" 
app:tabMode="scrollable"
android:layout_height="wrap_content" /> 
Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
tiny sunlight
  • 6,231
  • 3
  • 21
  • 42
-1

Once change the following code

<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="android:maxLines">1</item>
    <item name="android:singleLine">true</item>
</style>

to the following

<style name="MyCustomTabTextAppearance" parent="TextAppearance.AppCompat.Button">
    <item name="android:maxLines">1</item>
    <item name="android:singleLine">true</item>
</style>
Nigam Patro
  • 2,760
  • 1
  • 18
  • 33
-3

Add this line to your TabLayout custom style, it will do the magic.

<item name="android:maxLines">1</item>

Jerry Okafor
  • 3,710
  • 3
  • 17
  • 26