Skip to content

Instantly share code, notes, and snippets.

Last active Mar 29, 2018
What would you like to do?
override fun onCreate(savedInstanceState: Bundle?) {
story.text = writeFormattedStory()
private fun writeFormattedStory(): CharSequence {
return SpannableStringBuilder()
.append(createWithSpans("A Short Story", StyleSpan(Typeface.BOLD)))
.append("This is a short story")
.append(createWithSpans("fin.", StyleSpan(Typeface.ITALIC)))
private fun createWithSpans(charSequence: CharSequence, vararg spans: Any): SpannableString {
val spannableString = SpannableString(charSequence)
for (span in spans) {
spannableString.setSpan(span, 0, charSequence.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
return spannableString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment