Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text inside tabs of a TabLayout is not centered

I am using a TabLayout. I want full screen width to be filled by TabLayout, so I added app:tabGravity="fill". My problem is that now tab text is not centered. Here is a screenshot:

Please see pink bar under Tab one

The code of TabLayout is as follows:

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabTextColor="#d3d3d3"
        app:tabSelectedTextColor="#ffffff"
        app:tabIndicatorColor="#ff00ff"
        android:minHeight="?attr/actionBarSize"
        />

I have seen many questions but none of them solves my problem. Any help is highly appreciated. For details I want to tell that I am trying this example. Device is running on Android 2.3.6 (API 10). Screen is 320x240.

like image 906
Birendra Singh Avatar asked Jan 18 '17 19:01

Birendra Singh


2 Answers

Use this for adjusting the text:

android:gravity="center" OR android:textAlignment="center"

you should create a custom tab .. you are using these attributes for tabLayout which will not work ... the example link you provided above uses a file named custom_tab.xml . Use that for defining your textView and put these attributes inside it.

like image 165
MezzDroid Avatar answered Sep 19 '22 14:09

MezzDroid


just do like this:-

       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       app:tabMaxWidth="0dp"
       app:tabGravity="fill"
like image 36
M. H. Avatar answered Sep 22 '22 14:09

M. H.