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

Using a ColorStateList does not update color on state changed #5

Open
adamsp opened this issue Sep 12, 2016 · 0 comments
Open

Using a ColorStateList does not update color on state changed #5

adamsp opened this issue Sep 12, 2016 · 0 comments

Comments

@adamsp
Copy link

adamsp commented Sep 12, 2016

The color of the text does not update when used with a ColorStateList:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="@color/gray_6"/>
    <item android:state_selected="true" android:color="@color/gray_6"/>
    <item android:state_focused="true" android:color="@color/gray_6"/>
    <item android:color="@color/highlight_blue"/>
</selector>
textDrawable.setTextColor(getResources.getColorStateList(R.color.highlight_text));

This can be fixed by invalidating the view on state changed:

@Override
protected boolean onStateChange(int[] state) {
    // Upon state changes, grab the correct text color
    if (updateTextColors(state)) {
        invalidateSelf();
        return true;
    }
    return false;
}

I've tested this on 4.0.4, 4.4.2 and 6.0.1. Happy to send a PR if you'd like.

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

1 participant