I am using a TabLayout
and ViewPager
to display ActionBar tabs
following the guide Google Play Style Tabs using TabLayout, however my tabs are squished to the left side of the ActionBar, shown below:
And I would like them to take up the whole bar with equal widths. I've made only a few minor changes to the guide:
In activity_main.xml a style was created to show the ActionBar:
<android.support.design.widget.TabLayout android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/AppTheme" app:tabMode="scrollable" />
Here is the styles.xml code:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="windowActionBar">true</item> <item name="tabIndicatorColor">#ffff0030</item> </style>
Also, my MainActivity
now extends AppCompatActivity
instead of a FragmentActivity
.
It is possible to use a TabLayout without a ViewPager by using a TabLayout. OnTabSelectedListener . For navigation within an Activity , manually populate the UI based on the tab selected.
Tab layout are visible below toolbar with View pager, used to create swipeable views . Tabs are designed to work with fragments. Use them to swipe fragments in view pager.
Simple answer which I got from here.
You just put this in your xml code :
<android.support.design.widget.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:tabMaxWidth="0dp" app:tabGravity="fill" app:tabMode="fixed" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With