Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AndroidDeveloperLB opened this issue Feb 4, 2015 · 10 comments

Comments

@AndroidDeveloperLB
Copy link

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.

@AndroidDeveloperLB AndroidDeveloperLB changed the title set tabs text colors based on page selection Request (including code) : set tabs text colors based on page selection Feb 4, 2015
@bviebahn
Copy link

+1

@MewX
Copy link

MewX commented Feb 23, 2015

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

@ghost
Copy link

ghost commented Feb 26, 2015

+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
Copy link

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

@AndroidDeveloperLB
Copy link
Author

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

@ghost
Copy link

ghost commented Mar 13, 2015

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

@MewX
Copy link

MewX commented Mar 14, 2015

Hope this +1

@AndroidDeveloperLB
Copy link
Author

@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
Copy link

ghost commented Mar 15, 2015

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants