I'm trying to build a String that has two different custom fonts applied to it. I've appended the two strings with the respective font into a string builder, but this does nothing to the String at all? Does anyone know why?
private fun createSpannedNameAndComment(name: String, comment: String): SpannableStringBuilder {
val semiBoldFont = android.graphics.Typeface.create(
ResourcesCompat.getFont(
this,
R.font.josefin_san_semi_bold
), android.graphics.Typeface.NORMAL
)
val regularFont = android.graphics.Typeface.create(
ResourcesCompat.getFont(
this,
R.font.josefin_san_regular
), android.graphics.Typeface.NORMAL
)
return SpannableStringBuilder().apply {
append(name, semiBoldFont, 0)
append(" ")
append(comment, regularFont, 0)
}
}
You can use this custom
TypefaceSpan
class:And apply that to your the
SpannableStringBuilder
: