3

Ich versuche, eine Markierung der Farbe zu colorAccent gesetzt, aber irgendwie funktioniert es nicht mit diesem Code arbeiten:Tint ein Google Maps Android API Marker

Drawable drawable = getResources().getDrawable(R.drawable.ic_place_white_24dp); 
drawable.setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.MULTIPLY); 
BitmapDescriptor bitmap = BitmapDescriptorFactory.fromBitmap(((BitmapDrawable) drawable).getBitmap()); 
Bitmap workingBitmap = Bitmap.createBitmap(((BitmapDrawable) drawable).getBitmap()); 
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true); 
Canvas canvas = new Canvas(mutableBitmap); 
drawable.draw(canvas); 
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(mutableBitmap); 
markerOptions.icon(bitmapDescriptor); 

Ich versuchte, die ziehbar aus einem einfachen weißen Symbol zu wechseln zu einem schwarzen und versuchte auch, von Mode.MULTIPLY zu Mode.ADD zu wechseln. Beides ohne Erfolg.

Antwort

2

VERSUCHEN SIE DIESES !!!!

private static Paint markerPaint; 
private static Paint whitePaint; 

Bitmap markerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mapmarker); 
Bitmap resultBitmap = Bitmap.createBitmap(markerBitmap, 0, 0, markerBitmap.getWidth() - 1, markerBitmap.getHeight() - 1); 
ColorFilter filter = new PorterDuffColorFilter(Themer.getPrimaryColor(getActivity()), PorterDuff.Mode.SRC_IN); 
if (markerPaint == null) { 
    markerPaint = new Paint(); 
    markerPaint.setColorFilter(filter); 
} else { 
    markerPaint.setColorFilter(filter); 
} 
Canvas canvas = new Canvas(resultBitmap); 
canvas.drawBitmap(resultBitmap, 0, 0, markerPaint); 
if (Themer.shouldShowStopCounts(getActivity())) { 
    if (whitePaint == null) { 
     whitePaint = new Paint(); 
     whitePaint.setColor(Color.WHITE); 
     whitePaint.setTextSize(40f); 
     whitePaint.setTextAlign(Paint.Align.CENTER); 
    } 
    canvas.drawText(item.name, resultBitmap.getWidth()/2, resultBitmap.getHeight()/2, whitePaint); 
} 
markerOptions.icon(BitmapDescriptorFactory.fromBitmap(resultBitmap));