我想把标签文本(最多8个字符)放在单行
我为TabLayout元素添加了自定义样式
<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>
还是不行。我也试过了。
<android.support.design.widget.TabLayout
app:tabTextAppearance="@style/MyCustomTabTextAppearance"
..
..
/>
只需将app: tabMode="scrollable"
添加到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" />
一旦更改以下代码
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:maxLines">1</item>
<item name="android:singleLine">true</item>
</style>
对以下
<style name="MyCustomTabTextAppearance" parent="TextAppearance.AppCompat.Button">
<item name="android:maxLines">1</item>
<item name="android:singleLine">true</item>
</style>
将此行添加到您的TabLayout自定义样式中,它会起到神奇的作用。