AG is a mini-series on the quirks and idiosyncrasies of Android app development.

Using the XML attribute

I’ve set many drawableLefts and drawableRights on TextViews over the last few years.

Boom. Nice and easy.

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.

Rescue time

Here’s how to do it right:

With IntrinsicBounds

With DataBinding

With a Kotlin Extension

“The Drawable ’s bounds will be set to its intrinsic bounds.”

Click here for Part 2.

If you liked this post, hit the 👏 . Stay tuned for the next one!

Read other stuff I’ve written here. Share other quirks with me on Twitter!