Here’s a quick hack, a lot shorter than using setCustomView()
: use the android:theme
attribute on your TabLayout
:
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/TabLayout_Theme"
app:tabMode="fixed"/>
Then in your themes XML:
<style name="TabLayout_Theme" parent="@style/AppTheme">
<item name="android:singleLine">true</item>
</style>
We have to do it this way, because unfortunately the android:singleLine
attribute is ignored on the app:tabTextAppearance
set on the TabLayout. app:tabTextAppearance
is really only useful for changing text size.