Android maps v2 polygon transparency

I am using the Google Maps API v2 for Android and I am unable to control the fillColor transparency. I would like to see a map under a filled polygon. Is there any way to do this?

Thanks for any help!

+4
source share
3 answers

Ok, let me describe how the standard 4 byte color is encoded:

The standard pixel color consists of 4 bytes:

  • A (alpha channel) - 0-255 (0 - completely transparent, 255 - completely opaque)
  • R (red channel) - 0-255
  • G (green color channel) - 0-255
  • B (blue color channel) - 0-255

Each channel represents the saturation of a particular color portion. Therefore, if we need to create a fully opaque red color, we need to specify the following channel values:

  • 255,255,0,0

If we want to make it translucent, we need to divide the alpha channel value by 2 (255/2 = 127):

  • 127,255,0,0

So, back to the android. In Android, in most cases, you can specify a color by specifying its hexadecimal value:

polygon.setFillColor(0xFF00FF00); //not transparent green color

In hexadecimal mode, each channel can be specified by two hexadecimal digits:

  • A (FF)
  • R (00)
  • G (FF)
  • In (00)

If you want to make this color translucent, you need to divide FF by 2:

 0xFF/2 = 0x7F //the same as 255/2 = 127 

polygon.setFillColor(0x7F00FF00); //half-transparent green color

So basically, what you need to do is play with the alpha channel to get the transparency you're looking for.

+16
source
  cir=map.addCircle(new CircleOptions().center(new LatLng(10.938341, 76.9548734)) .radius(150) .strokeColor(Color.rgb(0, 50, 100)) .strokeWidth(5) .fillColor(Color.argb(20, 50, 0, 255)) .zIndex(55)); cir.setVisible(true); 
+4
source

Basically what worked for me is:

  polygon = mGoogleMap.addPolygon(new PolygonOptions(). addAll(points) .fillColor(0x33FF0000) .strokeColor(Color.RED) .strokeWidth(3)) 
0
source

All Articles