Quick tip - loading Android nine-patch drawables

Did you need to load a stretchy nine-patch drawable from your assets or the network, rather than directly via a resource? If so, you begin to realize that the foo.9.png file in your source is actually different from what's compiled into your apk, and you have to do something similar before you can use the goodness of NinePatchDrawables.

This aapt command converts a single input.9.png into a version that can be loaded as a NinePatchDrawable

aapt singleCrunch -v -i  input.9.png -o compiled_input.9.png

To load it within your code, simply use BitmapFactory to create a Bitmap from compiled_input.9.png, and then use

new NinePatch(mybitmap, mybitmap.getNinePatchChunk(), null)

to create a NinePatch, and then use that within a suitable NinePatchDrawable constructor to arrive at a nice, stretchable Drawable.