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

Added function to change tab title/icon color when selected. #62

Closed
wants to merge 4 commits into from

Conversation

red1004g
Copy link

Currently, only the interactive indicator can be modified in the tabs just like on the Google Play Store.
This modification allows selected tab title/icons to be of different color, making the interface more flexible and intuitive.
I added some functions in the library, and applied them on the sample.

library

  • pstsTabSwith(boolean) : When a tab is selected, the drawable selector icon or the text color of the Tab title can be modified
  • pstsActivateTextColor(int) : The Title color of selected Tab
  • pstsDeactivateTextColor(int) : The Title color of unselected Tabs

I believe these additions will diversify the usage of this project, paving the way for a better interface.

Thank you for sharing a great open source.

Comments and suggestions are welcome!

@austynmahoney
Copy link

These values should really be in a ColorStateList instead of being defined individually.

@HanderWei
Copy link

Thanks a lot!You solve my problem.And this is useful.

@ndy8791
Copy link

ndy8791 commented Mar 24, 2014

why in 2.3 PagerSlidingTabStrip with pstsTabSwith becomes like rainbow..
but it works good in android 4.2...

dsc_1942

@mygreymatter
Copy link

Mr.Red. Your work saved me a lot of time. Thank You.

@alendr
Copy link

alendr commented Sep 12, 2014

Greate work, but i have problem because icon not change on selected tab. I see when i pressed tab it's changed icon but when i release finger from tab it show me not selected icon, but change me text color of tab. Any solution ?

@lapastillaroja
Copy link

I think #83 implementation is cleaner
It uses ColorStateList

@alendr
Copy link

alendr commented Sep 12, 2014

lapastillaroja, but this is just for color change right ? What about icon change on selected tab too?

@lapastillaroja
Copy link

@ferrarif248
Your icon must be a drawable with states like this one

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/feed_selected"
          android:state_selected="true" />
    <item android:drawable="@drawable/feed_normal" />
</selector>

@alendr
Copy link

alendr commented Sep 12, 2014

I'v set in drawable selector_tab_1.xml like you wrote but didn't work. Do you maybe have some contact for chat ? if is not problem for you.

@camposbrunocampos
Copy link

Hello Guys, turns out that there is a better solution.
You could just create a selector resource inside res/colors/ and use it in your PagerSlidingStrip android:textColor attribute. I`ll print the code below.
The text will change its color like a selector button, simple like that. There is no need of changing the lib.

res/color/btn

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
        android:color="#000000" /> <!-- pressed -->
    <item android:state_focused="true"
        android:color="@color/active_text" /> <!-- focused -->
    <item android:color="#FFFFFF" /> <!-- default -->
</selector>

and here is where I use this resource in andorid:textColor attribute

slideFragment.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/pager_title"
        android:layout_width="match_parent"
        style="@style/PagerTitleStrip"
        android:layout_gravity="top"
        android:textColor="@color/btn"
        android:textSize="13sp"
        android:paddingBottom="@dimen/padding_logo"
        android:paddingTop="@dimen/padding_logo"
        app:pstsIndicatorColor="@color/border_title_strip"
        android:layout_height="@dimen/height_pager_title_strip"/>
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

    </android.support.v4.view.ViewPager>
</LinearLayout>

@PrathmK
Copy link

PrathmK commented Mar 19, 2015

can i set the custom tab width
if i want to set the 80% of the total width to the tab that is currently selected.

@alejouribesanchez
Copy link

Good work!!, thanks a lot!!!

@adityak74
Copy link

Saved a lot of time!! Thanks a lot!!!

@iamaunz
Copy link

iamaunz commented Apr 10, 2015

I got "No resource identifier found for attribute 'pstsTabSwitch'" when use app:pstsTabSwitch="true" any suggestion ?

@alxhotel
Copy link

alxhotel commented Jun 5, 2015

This works great !! Thanks

@vietmh
Copy link

vietmh commented Jul 6, 2015

I got the same problem with @iamaunz ("No resource identifier found for attribute 'pstsTabSwitch'").
What should I do ?
Should I download the code directly from github and push it into gradle file ?
I'm currently put "compile 'com.astuetz:pagerslidingtabstrip:1.0.1'" into gradle file.

deRonbrown referenced this pull request in deRonbrown/PagerSlidingTabStrip Dec 5, 2015
@rml-anh-nguyen
Copy link

rml-anh-nguyen commented May 9, 2016

@camposbrunocampos did anyone confirm this ? because it's not work in my project

@phitsanukae
Copy link

Lava600
เมื่อ 9 พ.ค. 2016 11:00 ก่อนเที่ยง "rml-anh-nguyen" <
notifications@github.com> เขียนว่า

@camposbrunocampos https://github.com/camposbrunocampos did anyone
confirm this ? because it's not work in mine project


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#62 (comment)

@UnateD
Copy link

UnateD commented May 9, 2016

@rml-anh-nguyen @devabir93 @vietmh @iamaunz @EugeneHoran @abhijith-gururaj
Pay attention to this link. Perhaps it is the same library, simply filled in another repository
https://github.com/jpardogo/PagerSlidingTabStrip

To change the color of the text is necessary to make drawable like
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/black" android:state_selected="true" /> <item android:color="#ff0000" android:state_selected="false" /> </selector>

and then apply to the property

app:pstsTabTextColor="@drawable/test"

Now the text color changes when the tab is active. In the description of the link has a lot of new properties

@red1004g red1004g closed this Sep 19, 2018
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

Successfully merging this pull request may close these issues.

None yet