如何改变SlidingTabLayout的文本颜色? [英] How to change the text color of SlidingTabLayout?

查看:565
本文介绍了如何改变SlidingTabLayout的文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做它使用的应用程序在 ActionBarCompat

I made an application which use the ActionBarCompat

我使用的 SlidingTabLayout 类创建的标签。

I created the tabs using the SlidingTabLayout class.

类是这样的:

<一个href="http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html">SlidingTabLayout.java

,但我不能改变标签的颜色...

but I can not change the color of the tabs...

我viewpager片段是这样的:

my viewpager fragment is this:

<swmovil.fyb.SlidingTabLayout
    android:id="@+id/mTabs"
    android:layout_width="match_parent"
    android:layout_height="48dip" />

<android.support.v4.view.ViewPager
    android:id="@+id/mPager"
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:layout_weight="1"
    android:background="@color/white" />

应用程序的伟大工程,但我不能改变标签的彩色文本

the application works great, but i can´t change the color text of the tabs...

我看到下面的例子后提出申请:

I made the application after seeing the following example:

<一个href="https://github.com/rudsonlive/Navigation-Drawer-ViewPager-ActionBarCompat">rudsonlive/Navigation-Drawer-ViewPager-ActionBarCompat

rudsonlive/Navigation-Drawer-ViewPager-ActionBarCompat

我如何更改选项卡文本的文本颜色?

How can i change the text color of the tabs text ?

谢谢!

推荐答案

1)首先建立在水库的颜色的文件夹(/ RES /彩色)
2)下创建/ RES xml文件selector.xml /彩色文件夹

1) First of all create color folder under res (/res/color)
2) create xml file selector.xml under /res/color folder

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@android:color/white" />
<item android:state_focused="true" android:color="@android:color/white" />
<item android:state_pressed="true" android:color="@android:color/white" />
<item android:color="#504f4f" /> 
</selector> 

3)然后在SlidingTabLayout的populateTabStrip()方法把这个

3) Then in the populateTabStrip() method in SlidingTabLayout put this

tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));

现在你有一个选择,你可以改变文本的颜色你想要的任何事件

now you have a selector and you can change the color of the text on any event you want

如果不工作增加了code以下行。
一)在populateTabStrip()方法,在末尾加上这个

if that is not working add the following lines of code.
a) in populateTabStrip() method at the end add this

if (i == mViewPager.getCurrentItem()) {
    tabView.setSelected(true);
}

和B)改变onPageSelected()方法,该

and b) change the onPageSelected() method to this

    @Override
    public void onPageSelected(int position) {
        if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
            mTabStrip.onViewPagerPageChanged(position, 0f);
            scrollToTab(position, 0);
        }
        for (int i = 0; i < mTabStrip.getChildCount(); i++) {
            mTabStrip.getChildAt(i).setSelected(position == i);
        }
        if (mViewPagerPageChangeListener != null) {
            mViewPagerPageChangeListener.onPageSelected(position);
        }
    }    

这篇关于如何改变SlidingTabLayout的文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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