I am trying to create nine patch images programmatically. I tried using the Griffey approach, but it seems like it can't get it to work. There is very little information on how to use the class. I am sure that I am importing the bitmap incorrectly. If anyone knows how to make this work or knows a better way, I really appreciate your help.
My code is:
// Dynamically create the 9patch image and apply it to a LinearLayout LinearLayout llcode = (LinearLayout) findViewById(R.id.llcode); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.white_button); Drawable np = NinePatchBitmapFactory.createNinePathWithCapInsets(getResources(), bitmap, 15, 15, 16, 16, null); llcode.setBackgroundDrawable(np); // The following code using the actual 9patch image: white_button_np.9.png LinearLayout llxml = (LinearLayout) findViewById(R.id.llxml); llxml.setBackgroundDrawable(getResources().getDrawable(R.drawable.white_button_np));
This screenshot shows a programming method on top and a typical 9patch method using the android tool at the bottom.
The original image before converting it to 9patch.
Have you tried to make the decoder configuration make sure there is an alpha channel?
inPreferredConfig ARGB_8888.
: fooobar.com/questions/146123/.... API 10.