splitwise / TokenAutoComplete

Gmail style MultiAutoCompleteTextView for Android
Apache License 2.0
1.3k stars 384 forks source link

How to add different text colors for different tokens ? #385

Closed iRaam closed 5 years ago

iRaam commented 5 years ago

Currently I am using this library for one of my project. I have a requirement to apply different color for different tokens in the recipient editor. How could I achieve that ?

@Override
    protected View getViewForObject(final ContactInfo contact) {
        LayoutInflater l = (LayoutInflater)getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        TokenTextView token = (TokenTextView) l.inflate(R.layout.contact_token, (ViewGroup) getParent(), false);
        if (!TextUtils.isEmpty(contact.getContactName())) {
            token.setText(contact.getContactName());
        } else {
            token.setText(contact.getContactNo());
        }
        if (contact.getUserProfile().isSubscribedUser()) {
            token.setTextColor(Color.YELLOW);
        } else {
            token.setTextColor(Color.RED);
        }
        return token;
    }

As of now, the token color changes to the color which I have in "contact_token.xml" when I add the next token.

iRaam commented 5 years ago

I made a mistake in TokenTextView class. In setSelected() I was changing the text color.