I have a Spannable Object
with a Clickable Object
set to it. When the Spannable String
is displayed in the TextView
it has bl
ANURAG RASTOGI's answer saved the day for me! I already have a formatted SpannableString
on which I wanted to apply a ClickableSpan
:
spannableString.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
// Do something...
}
// Prevent
// ds.setColor(ds.linkColor);
// ds.setUnderlineText(true);
// in: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/text/style/ClickableSpan.java
// from executing.
@Override
public void updateDrawState(@NonNull TextPaint ds) {
// super.updateDrawState(ds);
}
},0, spannableString.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
The updateDrawState
overrides the updateDrawState
in the ClickableSpan
class in Android, and by not calling super.updateDrawState
it will not get executed.
All text formatting already present in spannableString
will be preserved.