Android Design Support Library: TabLayout tabs text in single line [duplicate]
Asked Answered
H

3

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"
  ..
  ..
  />
Hambletonian answered 1/1, 2016 at 10:31 Comment(4)
guides.codepath.com/android/…Bolding
This might be the solution that you are looking for. :)Promptbook
Just add app:tabMode="scrollable ;<android.support.design.widget.TabLayout android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" />Muller
solved my problem by this answer see this answerMadrepore
M
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" /> 
Muller answered 1/1, 2016 at 10:41 Comment(0)
I
-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>
Islamism answered 1/1, 2016 at 10:34 Comment(1)
add this style as theme to tablayout xmlGlossal
A
-3

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

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

Aaronson answered 2/11, 2018 at 15:50 Comment(1)
I tried using this, but its not workingToast

© 2022 - 2024 — McMap. All rights reserved.