Created
July 15, 2021 04:53
-
-
Save thegarlynch/ad26d0ce385c2ea2c80fd40d32edc329 to your computer and use it in GitHub Desktop.
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
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