Closed elliottsj closed 9 years ago
http://stackoverflow.com/questions/25402452/attempting-to-get-attribute-values-in-code-returns-incorrect-values
It turns out that the ATTRS
array needs to be sorted in ascending order, thanks to the way Android iterates over the attributes deep in its C++ source.
Sorting ATTRS
in ascending order should fix the issue:
private static final int[] ATTRS = new int[]{
android.R.attr.textColorPrimary,
android.R.attr.textSize,
android.R.attr.textColor,
android.R.attr.paddingLeft,
android.R.attr.paddingRight
};
I'll do some testing to make sure it works and make a PR
Submitted an issue to Android: https://code.google.com/p/android/issues/detail?id=91445
Why do you use android:textColorPrimary="@android:color/white"
? this attr doesn't exist. You should use android:textColor="@android:color/white"
android:textColorPrimary
is defined in the app theme, so I thought you should be able to override theme attributes like this on a view-by-view basis.
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:textColorPrimary="@android:color/white"
app:pstsShouldExpand="true" />
Should be equivalent to
<com.astuetz.PagerSlidingTabStrip
style="@style/TabStrip"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
app:pstsShouldExpand="true" />
<!-- res/values/styles.xml -->
...
<style name="TabStrip">
<item name="android:textColorPrimary">@android:color/white</item>
</style>
...
Sorry I got confuse, yes we need android.R.attr.textColor
and android.R.attr.textColorPrimary
https://github.com/jpardogo/PagerSlidingTabStrip/blob/master/library/src/com/astuetz/PagerSlidingTabStrip.java#L163
If I specify the
textColorPrimary
as an attribute of the view (or if I specify it in a theme via thestyle
attribute), the value is ignored andtextColorPrimary
from the parent theme is used instead.(i.e. the
@android:color/white
value is ignored)I've tried breaking on this line (PagerSlidingTabStrip.java#L156) to see if
obtainStyledAttributes
is returning the right attributes:While paused, running the expression
gives me the correct value of
"#ffffffff"
. But runninggives me the incorrect value of
"#ff212121"
(from the parent theme).Then, stepping past L#159,
int textPrimaryColor
has that same incorrect value (converted to an int):-14606047
(== 0xFF212121
)I'm wondering if this is an Android issue because
should really be the same value as