Custom font color for PagerTabStrip in ViewPager for my Android app

梦想的初衷 提交于 2020-01-01 10:57:10

问题


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>

回答1:


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.




回答2:


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);



回答3:


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));
    }
}



回答4:


Why don't you use:

pagerTabStrip.setTextColor(int color);



来源:https://stackoverflow.com/questions/13398471/custom-font-color-for-pagertabstrip-in-viewpager-for-my-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!