Last active
March 29, 2018 21:32
-
-
Save ataulm/19bbbf0a838b746c6a40d0bb0314a053 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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_my) | |
story.text = writeFormattedStory() | |
} | |
private fun writeFormattedStory(): CharSequence { | |
return SpannableStringBuilder() | |
.append(createWithSpans("A Short Story", StyleSpan(Typeface.BOLD))) | |
.append("\n") | |
.append("This is a short story") | |
.append("\n") | |
.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