Skip to content
This repository has been archived by the owner on Mar 19, 2022. It is now read-only.

how do I set color of the label #11

Open
shahimclt opened this issue Nov 2, 2017 · 5 comments
Open

how do I set color of the label #11

shahimclt opened this issue Nov 2, 2017 · 5 comments

Comments

@shahimclt
Copy link

shahimclt commented Nov 2, 2017

The GIF in the readme shows labels with different colors:

demo

but I don't see any mention of how to do that. Please advise.

@shahimclt
Copy link
Author

I dug through the code a little bit and I think adding a new method getLabelColor to DateLabelAdapter will do the trick. @badoualy what do you think?

@badoualy
Copy link
Owner

badoualy commented Nov 2, 2017

If memory serves, for this case I used CharSequence with ForegroundColorSpan
I'll check for the label color, I'll add when I have some time (or you can if you want to do a PR).

@shahimclt
Copy link
Author

shahimclt commented Nov 2, 2017

Wow. I didn't know you could do that with a CharSequence. So thanks a lot for that.

This is what I am going with :

public CharSequence getLabel(Calendar calendar, int index) {
  SpannableStringBuilder builder = new SpannableStringBuilder();
  String red = "full";
  SpannableString redSpannable= new SpannableString(red);
  redSpannable.setSpan(new ForegroundColorSpan(Color.BLUE), 0, red.length(), 0);
  builder.append(redSpannable);
  return builder;
}

So now I suppose there is no need for a PR. Maybe you can include this snippet in the readme so that others can benefit.

@badoualy
Copy link
Owner

badoualy commented Nov 2, 2017

Yeah, but using span if you're always using the same color is not the best idea, complicates life for nothing :)
Tip, following code is simpler/more optimized:

SpannableString span = new SpannableString("full");
span.setSpan(new ForegroundColorSpan(Color.BLUE), 0, span.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
return span;

@shahimclt
Copy link
Author

Yes, I did that. The code I posted was a generic one lifted from Stack Overflow. I am using the simpler version in my project. Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants