Android:Google地图片段中的Iconify标记图标是透明的

时间:2016-03-30 02:36:03

标签: android google-maps icons google-maps-markers

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

如上图所示,我在SupportMapFragment上创建的Iconify库中的自定义地图标记是透明的。如何使这些标记不透明?

以下是我在地图上绘制标记的方法:

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);

以下是birthEvent

中定义颜色res/values/colors.xml的方式
<resources>
    <color name="birthEvent">#FD3C3C</color>
</resources>

1 个答案:

答案 0 :(得分:1)

  

在   markerOptions.alpha()   方法应指定为介于0.0和1.0之间的浮点数,其中0为   完全透明,1完全不透明。因此,尝试将其更改为   漂浮在0到1之间。

或者您可以查看blog如何在MapFragment中设置Android iconify。

以下是示例代码。

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);
}