2

I want to add letter in default marker of Google map. It should look like

this.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163

1 Answers1

2

This method takes a drawable from your resources, draws some text on top of it(inside the marker) and returns the new drawable. All you need to do is give it the resource id of your bubble, and the text you want on top. Then you can pass the returned drawable wherever you want it.

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 preserver density you need this constructor

BitmapDrawable (Resources res, Bitmap bitmap)

So, keeping your context, last return should be something like

    return new BitmapDrawable(context.getResources(), bm);

This prevent an undesired resized drawable.

Dharamveer
  • 36
  • 4