自定义字体颜色PagerTabStrip在ViewPager我的Andr​​oid应用 [英] Custom font color for PagerTabStrip in ViewPager for my Android app

查看:261
本文介绍了自定义字体颜色PagerTabStrip在ViewPager我的Andr​​oid应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更改PagerTabStrip在ViewPager字体颜色为我的Andr​​oid应用程序。这是对于相同的XML布局。有没有什么办法可以做到这一点?

 < android.support.v4.view.ViewPager
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:layout_below =@ ID /头
    机器人:ID =@ + ID / myfivepanelpager>        < android.support.v4.view.PagerTabStrip
         机器人:ID =@ + ID / pgstrip
        机器人:layout_width =FILL_PARENT
        机器人:背景=@彩色/条
        机器人:layout_height =@扪/ pagerstripht
        机器人:layout_gravity =顶
        />    < /android.support.v4.view.ViewPager>


解决方案

获取PagerTabStrip的孩子意见,并检查它是否是一个TextView的实例。如果是,设置文本颜色:

  PagerTabStrip mPagerTabStrip =(PagerTabStrip)findViewById(R.id.pgstrip);
的for(int i = 0; I< mPagerTabStrip.getChildCount(); ++ I){
    视图nextChild = mPagerTabStrip.getChildAt(ⅰ);
    如果(nextChild的instanceof的TextView){
        TextView的textViewToConvert =(TextView中)nextChild;
        textViewToConvert.setTextColor(getResources()的getColor(R.color.primary_text_color_dark_gray));
    }
}

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>

解决方案

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

这篇关于自定义字体颜色PagerTabStrip在ViewPager我的Andr​​oid应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆