Android Gotchas: #1 Setting a Drawable on a TextView programmatically
AG is a mini-series on the quirks and idiosyncrasies of Android app development.
Using the XML attribute
I’ve set many
TextViews over the last few years.
Never had to set it programatically, yet.
Setting compound drawables
Well, it doesn’t work. ¯\_(ツ)_/¯
After wasting an hour and pulling half my hair out, I noticed I had overlooked an important detail in the JavaDoc.
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text......The Drawables must already have had Drawable.setBounds called.
Here’s how to do it right:
With a Kotlin Extension
Click here for Part 2.