0

In my application I have a 9.png. If I set it in XML via

android:background="@drawable/image"

it works great but if I use this code: bubble.setBackgroundResource(R.drawable.image) to set the 9.png programmaticly it does not work. Any ideas why?

Cilenco
  • 6,951
  • 17
  • 72
  • 152
  • Of course: you are applying a **background**, not a **NinePatchDrawable**... see here: http://stackoverflow.com/a/10639923/2649012 – Phantômaxx Apr 16 '14 at 13:13

2 Answers2

1

Try this :

private Drawable displayNinePatch(Bitmap bitmap, Context context) {
    byte[] chunk = bitmap.getNinePatchChunk();
    if(NinePatch.isNinePatchChunk(chunk)) {
        return new NinePatchDrawable(context.getResources(), bitmap, chunk, new Rect(), null);
    } else return new BitmapDrawable(bitmap);
}
kAnNaN
  • 3,669
  • 4
  • 28
  • 39
0

img_image.setBackground(getResources().getDrawable( R.drawable.icon));

Digvesh Patel
  • 6,503
  • 1
  • 20
  • 34