Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom font color for PagerTabStrip in ViewPager for my Android app

I need to change the font color for PagerTabStrip in ViewPager for my Android app. This is the xml layout for the same. Is there any way I can do this?

<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/head"
    android:id="@+id/myfivepanelpager">

        <android.support.v4.view.PagerTabStrip
         android:id="@+id/pgstrip"
        android:layout_width="fill_parent"
        android:background="@color/strip"
        android:layout_height="@dimen/pagerstripht"
        android:layout_gravity="top"
        />

    </android.support.v4.view.ViewPager>
like image 988
ambit Avatar asked Nov 15 '12 13:11

ambit


3 Answers

in your code :

<android.support.v4.view.PagerTabStrip
         android:id="@+id/pgstrip"
        android:layout_width="fill_parent"
        android:background="@color/strip"
        android:layout_height="@dimen/pagerstripht"
        android:layout_gravity="top"
        />

I think adding android:textColor="#000" will change the text color.

like image 102
Wuit Yi Avatar answered Jan 03 '23 16:01

Wuit Yi


If you haven't found out yet, code is below

PagerTabStrip pagerTabStrip = (PagerTabStrip) findViewById(R.id.pager_title_strip);
pagerTabStrip.setDrawFullUnderline(true);
pagerTabStrip.setTabIndicatorColor(Color.RED);
like image 31
Royston Pinto Avatar answered Jan 03 '23 16:01

Royston Pinto


Get the child views of the PagerTabStrip and check if it is an instance of a TextView. If it is, set text color:

PagerTabStrip mPagerTabStrip = (PagerTabStrip) findViewById(R.id.pgstrip);
for (int i = 0; i < mPagerTabStrip.getChildCount(); ++i) {
    View nextChild = mPagerTabStrip.getChildAt(i);
    if (nextChild instanceof TextView) {
        TextView textViewToConvert = (TextView) nextChild;
        textViewToConvert.setTextColor(getResources().getColor(R.color.primary_text_color_dark_gray));
    }
}
like image 25
sdex Avatar answered Jan 03 '23 14:01

sdex