android - How can I create same sized tabs in TabLayout -
i using designsupportlibrary (v22.2.0) , want tabs in tablayout same width - regardless tab text length. have tried mode_fixed still shows tabs different widths. here xml:
<android.support.design.widget.tablayout android:id="@+id/tab_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?attr/colorprimary" android:theme="@style/themeoverlay.appcompat.dark.actionbar" app:tabmode="fixed"/>
if want specify minimum width each tab, can set in style:
<style name="mytablayoutstyle" parent="themeoverlay.appcompat.dark.actionbar"> <item name="tabminwidth">100dp</item> </style>
and set theme style instead (you can delete tabmode attribute well):
<android.support.design.widget.tablayout android:id="@+id/tab_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?attr/colorprimary" android:theme="@style/mytablayoutstyle"/>
alternately, can set tabminwidth directly on tablayout:
<android.support.design.widget.tablayout android:id="@+id/tab_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?attr/colorprimary" android:theme="@style/themeoverlay.appcompat.dark.actionbar" app:tabminwidth="100dp"/>
an additional note: looks mode_fixed not work unless define layout_width of tablayout (instead of using "wrap_content"). tabs still expand match widest tab (as determined longest length of text). if defined width larger generated tabs. there empty space right of tabs.
Comments
Post a Comment