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

Remove selected text color attribute #70

Closed
wants to merge 3 commits into from

Conversation

@ataulm
Copy link

commented Feb 21, 2015

This removes the custom attribute for tab text color selected, replacing it with the standard behaviour of android:textColor.


Default case, with no textColor specified:

<com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:pstsPaddingMiddle="true" />

default_no_color_specified


Expected best case, with textColor specified with a custom color state list resource:

<com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:textColor="@color/my_custom_tab_color_state_list"
        app:pstsPaddingMiddle="true" />

color_state_list_specified


Case with textColor specified with a color resource that's just a single color:

<com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:textColor="@android:color/holo_green_light"
        app:pstsPaddingMiddle="true" />

single_color_resource_specified


Case with textColor specified with a hex value:

<com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:textColor="#ef23f1"
        app:pstsPaddingMiddle="true" />

single_hex_color_specified

ataulm added 3 commits Feb 21, 2015
- using android:textColor attribute you can specify a color resource or
a hex value
- if you specify a color state list, supported states are selected,
focused and default
- if you don't specify anything, it'll use the default_tab_text.xml
color resource which behaves almost like the original sample (50% alpha
instead of 150/255) for unselected tab text
@ataulm

This comment has been minimized.

Copy link
Author

commented Feb 21, 2015

@jpardogo Opened this PR just so you can see what I mean, not specifically asking for a merge as it's API breaking again (on that note, can you clean dev so it matches master, so new PRs can be done against dev?)

As selected state is part of View, you can use this to choose (or rather let the system choose) the right color for the text by calling tabTextView.setSelected(true | false) at the right times.

@jpardogo

This comment has been minimized.

Copy link
Owner

commented Feb 21, 2015

I will clean dev, match to master and start to do a proper git flow. I have been just lazy, but you are right.

That makes completely sense. The are two reasons I didn´t do it this way:

1 - Different tab selectors for non selected tabs and selected tab (I think someone open an issue about that long ago )

2 - I thought that once selected, the pressed state wasn´t gonna work for the selected tab text color (we have setOnTabReselectedListener) but I was wrong (I have just checked) because all depends of the order of the items.

Like that pressed state color work in the already selected tab.

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:color="#3e3" android:state_pressed="true" />
  <item android:color="#FFFFFF" android:state_selected="true" />
  <item android:color="#80FFFFFF" />
</selector>

Like that it doesn´t:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:color="#FFFFFF" android:state_selected="true" />
  <item android:color="#3e3" android:state_pressed="true" />
  <item android:color="#80FFFFFF" />
</selector>

Should we follow this approach and remove the possibility of different selectors (on non selected and selected tabs ) for the sake of the simplicity?

@ataulm

This comment has been minimized.

Copy link
Author

commented Feb 21, 2015

Yep exactly, selectors work from top to bottom and pick the first match.

I think it'd be best to do that, even if just to make the class simpler for
you to maintain.

For people doing funky things, they can provide their own tab layout - I
think @ouchadam had ideas on that.
On 21 Feb 2015 17:30, "Javier Pardo de Santayana Gómez" <
notifications@github.com> wrote:

I will clean dev, match to master and start to do a proper git flow. I
have been just lazy, but you are right.

That makes completely sense. The are two reason I didn´t do it this way:

1 - Different tab selector for non selected tabs and selected tab (I think
someone open an issue about that long ago )
2 - I thought that once selected the pressed state wasn´t gonna work to
change the selected tab text color but I was wrong (I have just checked)
because all depends of the order of the items.

Like that pressed state color work in the already selected tab.

Like that it doesn´t:

Should we follow this approach and remove the possibility of different
selectors (on non selected and selected tabs ) for the sake of the
simplicity?

Reply to this email directly or view it on GitHub
#70 (comment)
.

@jpardogo

This comment has been minimized.

Copy link
Owner

commented Feb 21, 2015

I agree people is driving me a bit crazy with his designs....

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?android:textColorPrimary" android:state_selected="true" />

This comment has been minimized.

Copy link
@jpardogo

jpardogo Feb 21, 2015

Owner

isn't ?android:textColorPrimary available in pre L releases?

This comment has been minimized.

Copy link
@ataulm

ataulm Feb 21, 2015

Author

Yes, you're right, it's available. Doesn't look like it can be used as a color attribute though, weirdly - it doesn't resolve to the correct color (the resource ID gets parsed as the color, rather than resolving it). Using it as a drawable resource, like for a background, seems to work. So confused.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?android:textColorPrimary" android:state_selected="true" />
<item android:color="#80FFFFFF" />

This comment has been minimized.

Copy link
@jpardogo

jpardogo Feb 21, 2015

Owner

We are not going to be able to generate android:textColorPrimary with 150 alpha this way. So we need to rely in half transparent white. That´s another downside. It is nice to have default colours as your theme.

@jpardogo

This comment has been minimized.

Copy link
Owner

commented Feb 21, 2015

I think I will leave it like it is for this version 1.0.9.
I will push it tomorrow to maven and I will think about this approach for a future release. Before I push the lib I would like to clarify the issue #68 for tomorrow with @ouchadam , otherwise I will push like that.

@ataulm ataulm closed this Feb 21, 2015
@jpardogo jpardogo reopened this May 18, 2015
jpardogo added a commit that referenced this pull request May 20, 2015
- Change order attr. Now the order is the same in attr.xml
and java class constructor.
- Better attr names, every attr related with tabs start with pstsTab
- Android attr only use for container
- No flipping the styles/appearance on selection/deselection tabs
- Remove custom attire `pstsTextColorSelected ` and
`pstsTextSelectedStyle `
- Callbacks for selection/deselection of tabs passing the tab view as
parameter when custom tabs are use.
@jpardogo jpardogo closed this May 20, 2015
@yugeshdevaraja

This comment has been minimized.

Copy link

commented Jun 25, 2015

How can i add the selected tab in one color tab in Unselected tab in another Color.

In Previous version you provided
app:pstsTextColorSelected="@color/primary_color" for changeing selected tab text color.
Now you changed this app:pstsTextColorSelected to pstsTabTextColor, current one show all the texts in same for both Select and Unselected Tab Texts.

How can i change the Selected Tab Text color in this version.

@ataulm

This comment has been minimized.

Copy link
Author

commented Jun 25, 2015

@yugeshdevaraja There's a note on the README explaining how to do this now. See issue #68 for more information about why it was changed.

pstsTabTextColor is the attribute to which you will need to assign a ColorStateList.

A ColorStateList is a scary name for something that's not actually that bad - it just represents a list of colors which will be used depending on the state of the view.

In this case, you'll need to provide the default and selected (or activated, correct me if I'm wrong @jpardogo) states.

Create res/color/tab_text.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_selected="true" android:color="@color/tab_text_selected" />
  <item android:color="@color/tab_text_default" />
</selector>

where @color/tab_text_selected and @color/tab_text_default are just color resources in your res/values/colors.xml file, e.g.:

<color name="tab_text_selected">#FFFFFF</color>

Then you can assign this ColorStateList to the attribute:

app:pstsTabTextColor="@color/tab_text"
@yugeshdevaraja

This comment has been minimized.

Copy link

commented Jun 26, 2015

@ataulm Thanks 👍

@AbhilashReddy17

This comment has been minimized.

Copy link

commented Aug 16, 2017

@ataulm thanks thats a perfect solution for changing the selected tab colour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.