This method extracts resources from your resources, draws text above it and returns a new one. All you have to do is give it the resource ID of your bubble and the text you want on top. You can then pass the returned drawing wherever you want.
public BitmapDrawable writeOnDrawable(int drawableId, String text){
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.BLACK);
paint.setTextSize(20);
Canvas canvas = new Canvas(bm);
canvas.drawText(text, 0, bm.getHeight()/2, paint);
return new BitmapDrawable(bm);
}
Note:
To maintain density, you will need this constructor
BitmapDrawable (Resources res, Bitmap bitmap)
, , -
return new BitmapDrawable(context.getResources(), bm);
.