colelemonz
colelemonz

Reputation: 1329

Android: Iconify marker icon in Google Map Fragment is transparent

The custom map markers are transparent, I want them to be opaque.

As one can see in the image above, the custom map markers from the Iconify library that I create on a SupportMapFragment are transparent. How can I make these markers opaque?

Here is how I draw the markers on the map:

IconDrawable icon = new IconDrawable(getActivity(), Iconify.IconValue.fa_map_marker)
    .colorRes(R.color.birthEvent)
    .sizeDp(40);
icon.setAlpha(255);

Canvas canvas = new Canvas();
Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
canvas.setBitmap(bitmap);
icon.draw(canvas);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);

MarkerOptions marker = new MarkerOptions()
    .icon(bitmapDescriptor);
googleMap.addMarker(marker);

Here is how the color birthEvent is defined in res/values/colors.xml:

<resources>
    <color name="birthEvent">#FD3C3C</color>
</resources>

Upvotes: 2

Views: 1164

Answers (1)

KENdi
KENdi

Reputation: 7751

The markerOptions.alpha() method should be specified as a float between 0.0 and 1.0, where 0 is fully transparent and 1 is fully opaque. So try to change it as a float between 0 to 1.

Or you can check this blog on how to set the Android iconify in MapFragment.

Here is the example code.

public BitmapDescriptor getCustomMarker(IconValue iconValue) {  
    IconDrawable id = new IconDrawable(getBaseContext(), iconValue) {
         @Override
         public void draw(Canvas canvas) {
             // The TextPaint is defined in the constructor
            // but we override it here
            TextPaint paint = new TextPaint();
            paint.setTypeface(Iconify.getTypeface(getBaseContext()));
            paint.setStyle(Paint.Style.STROKE_AND_FILL);
            paint.setTextAlign(Paint.Align.CENTER);
            paint.setUnderlineText(false);

            // If you need a custom color specify it here
            paint.setColor(Color.BLACK);

            paint.setAntiAlias(true);
            paint.setTextSize(getBounds().height());
            Rect textBounds = new Rect();
            String textValue = String.valueOf(iconValue.character());
            paint.getTextBounds(textValue, 0, 1, textBounds);
            float textBottom = (getBounds().height() - textBounds.height()) / 2f + textBounds.height() - textBounds.bottom;
            canvas.drawText(textValue, getBounds().width() / 2f, textBottom, paint);
        }

    }.actionBarSize();
     Drawable d = id.getCurrent();
    Bitmap bm = Bitmap.createBitmap(id.getIntrinsicWidth(), id.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bm);

    d.draw(c);

    return BitmapDescriptorFactory.fromBitmap(bm);
}

Upvotes: 1

Related Questions