Last active
January 3, 2023 07:15
-
-
Save victory316/46cf3d166cb046dd5b25ce61f220a031 to your computer and use it in GitHub Desktop.
Multiple Spanned Text BindingAdapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@BindingAdapter( | |
"multipleSpannedText" | |
) | |
fun setCommentItem( | |
textView: TextView, | |
multipleSpannedText: String | |
) { | |
val clickableSpanText = commentItem.comment.formattedComment | |
val clickableSpan = object : ClickableSpan() { | |
override fun onClick(widget: View) { | |
} | |
override fun updateDrawState(ds: TextPaint) { | |
ds.linkColor = textView.context.getColor(R.color.black) | |
} | |
} | |
val endPosition = clickableSpanText.indexOfFirst { it == ' ' } | |
textView.apply { | |
linksClickable = true | |
isClickable = true | |
movementMethod = LinkMovementMethod.getInstance() | |
highlightColor = Color.TRANSPARENT | |
} | |
clickableSpanText.toSpannable().apply { | |
setSpan( | |
TextAppearanceSpan(textView.context, R.style.Subtitle2), | |
0, | |
endPosition, | |
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | |
) | |
setSpan(clickableSpan, 0, endPosition, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) | |
}.also { | |
textView.text = it | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment