astuetz / PagerSlidingTabStrip

An interactive indicator to navigate between the different pages of a ViewPager
139 stars 44 forks source link

Request (including code) : set tabs text colors based on page selection #178

Open AndroidDeveloperLB opened 9 years ago

AndroidDeveloperLB commented 9 years ago

I'd like to suggest adding this feature, and I've even tried something that made it work well:

add those attributes:

    <attr name="pstsTabSelectedTextColor" format="color" />
    <attr name="pstsTabUnselectedTextColor" format="color" />

in the "PagerSlidingTabStrip" file, add those:

private static final int DEFAULT_TAB_TEXT_COLOR = 0xFF666666;
private  int tabSelectedTextColor;
private  int tabUnselectedTextColor;

remove the "tabTextColor" field and anything that is related to it.

in the CTOR, add this:

    tabSelectedTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTabSelectedTextColor, DEFAULT_TAB_TEXT_COLOR);
    tabUnselectedTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTabUnselectedTextColor, DEFAULT_TAB_TEXT_COLOR);

in the code, add setters&getters for the new fields I've written. Add this method:

private void updateTabsTextColors() {
    for (int i = 0; i < tabCount; i++) {
        View v = tabsContainer.getChildAt(i);
        if (v instanceof TextView) {
            TextView tab = (TextView) v;
            if (pager.getCurrentItem() == i)
                tab.setTextColor(tabSelectedTextColor);
            else tab.setTextColor(tabUnselectedTextColor);
        }
    }
}

call this function inside "onPageSelected" of the "PageListener" class, in the new setters, and in the end of "updateTabStyles" .

That's it.

bviebahn commented 9 years ago

+1

MewX commented 9 years ago

I hope I can use "tabs.setActivateTextColor(...)" function in the coming version.

ghost commented 9 years ago

+1

You already made a pull request? If not, can you provide a gradle compile like dependencies { compile 'com.astuetz:pagerslidingtabstrip:1.0.1' } So we can use your branch?

mkotsollaris commented 9 years ago

Do you have any fork of your solution, in order to avoid deep copying the project?

AndroidDeveloperLB commented 9 years ago

I don't know how to do the pull request. What should I do exactly ?

ghost commented 9 years ago

oh boy, here we go! xD @AndroidDeveloperLB hope this helps :3

MewX commented 9 years ago

Hope this +1

AndroidDeveloperLB commented 9 years ago

@vyscond OK, since I'm now at home, and the suggestion was written at the office, I had to get the project into Android-Studio, but now I see this:

untitled20150314130619

Why does it occur?

ghost commented 9 years ago

@AndroidDeveloperLB

  1. thanks for the effort to make this feature available. this the spirit of github :)
  2. i'm sorry but i can't help you with this one. right now i'm 4 months old using Android Studio and i didn't use this feature of import from gradle.
  3. This type of question is more about usage and not only/specific about the project/library on the repo, so better not posting things like this around here. You may have more lucky at OS to solve this one.
AndroidDeveloperLB commented 9 years ago

@vyscond But I didn't do anything special... And I have succeeded importing the project before. Something went wrong. Please help.