Skip to content

Instantly share code, notes, and snippets.

@victory316
Last active January 3, 2023 07:15
Show Gist options
  • Save victory316/46cf3d166cb046dd5b25ce61f220a031 to your computer and use it in GitHub Desktop.
Save victory316/46cf3d166cb046dd5b25ce61f220a031 to your computer and use it in GitHub Desktop.
Multiple Spanned Text BindingAdapter
@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