Question

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?

Was it helpful?

Solution

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);
}

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top