added ColoredUrlSpan

This commit is contained in:
gorodeckii 2017-07-04 12:35:17 +03:00
parent aee975833a
commit 838faf8e8c
1 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,32 @@
package ru.touchin.roboswag.components.utils.spans;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.text.TextPaint;
import android.text.style.URLSpan;
/**
* URLSpan that takes custom color and doesn't have the default underline.
* Don't forget to use
* textView.setMovementMethod(LinkMovementMethod.getInstance());
* and
* textView.setText(spannableString, TextView.BufferType.SPANNABLE);
*/
public class ColoredUrlSpan extends URLSpan {
@ColorInt
private final int textColor;
public ColoredUrlSpan(@ColorInt final int textColor, @NonNull final String url) {
super(url);
this.textColor = textColor;
}
@Override
public void updateDrawState(@NonNull final TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setColor(textColor);
}
}