Skip to content

Instantly share code, notes, and snippets.

@thegarlynch
Created July 15, 2021 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thegarlynch/ad26d0ce385c2ea2c80fd40d32edc329 to your computer and use it in GitHub Desktop.
Save thegarlynch/ad26d0ce385c2ea2c80fd40d32edc329 to your computer and use it in GitHub Desktop.
object StringUtil {
/**
* String Format :
*
* <<Regular Text>> <<Clickable Bold Text>>
*
* Don't forget this line to made clicking work,
* apply it into textView.
*
* textView.movementMethod = LinkMovementMethod.getInstance();
*
*/
fun promptString(
regularText : String,
clickableBoldText : String,
@ColorInt regularColor : Int = "#ABFFFFFF".toColorInt(),
@ColorInt clickableBoldColor: Int = "#E1E1E1".toColorInt(),
onClick : () -> Unit
) : SpannedString {
val clickableSpan = object : ClickableSpan() {
override fun onClick(widget: View) {
onClick.invoke()
}
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.isUnderlineText = false
}
}
return buildSpannedString {
color(regularColor) {
append(regularText)
}
append(" ")
bold {
color(clickableBoldColor){
inSpans(clickableSpan){
append(clickableBoldText)
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment