Android Set Image in TextView Through Spanned String

The example below replace * is string with an drawable image.

val googleText = SpannableStringBuilder("* Hello").apply {
    setSpan(ImageSpan(context, R.drawable.powered_by_google_dark), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

textView.text = googleText

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.