Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabs in TabLayout not filling up entire ActionBar

Tags:

java

android

tabs

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.

like image 368
clever_trevor Avatar asked Jun 09 '15 01:06

clever_trevor


People also ask

Can we use TabLayout without ViewPager in Android?

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.

How do I use TabLayout with ViewPager?

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.


1 Answers

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" /> 
like image 169
Parth Anjaria Avatar answered Sep 22 '22 11:09

Parth Anjaria