1

We are testing our new app and we use compound drawables for several textviews. Unfortunately the Sony Xperia S (LT26i) ignores setCompoundDrawables & setCompoundDrawablesWithIntrinsicBounds.

Can anybody confirm this bug? Or does anybody have a working workaround? Does this effect affect other phones?

Thanks and greets

Benjamin
  • 451
  • 3
  • 6
  • Maybe related: http://stackoverflow.com/questions/6590838/calling-setcompounddrawables-doesnt-display-the-compound-drawable, but I couldn't find any bugs related with either Xperia or `setCompoundDrawables()` – Andrew T. Aug 22 '14 at 08:40

2 Answers2

3

I can confirm the same behavior on my LT26i/4.1.2/build 6.2.B.1.96.

My workaround is to clear all compound drawables before reassigning with proper drawables:

final int oldPadding = getCompoundDrawablePadding();

// In order to be able to reset the drawables, set padding to zero.
// (this step is specific to this Android issue/bug)
setCompoundDrawablePadding(0);
// Reset drawables
setCompoundDrawables(null, null, null, null);

// Set drawables and restore padding
setCompoundDrawables(myDrawables[0], myDrawables[1], myDrawables[2], myDrawables[3]);
setCompoundDrawablePadding(oldPadding);
Melv
  • 983
  • 6
  • 13
3

I found the same behaviour on an Xperia S (LT26i) too. I tried it on several different devices including other 4.1.2 devices and it was the only one with the error. I modified Melv's answer (thanks very much, I had no idea why this was happening!)

TextView title = ....

title.setCompoundDrawablePadding(0);
// Reset drawables
title.setCompoundDrawables(null, null, null, null);
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawableId, 0);
ryanjohn
  • 86
  • 4