Set map marker to a custom color Android

独自空忆成欢 提交于 2019-12-05 03:05:27
Leszek Jasek

defaultMarker() method allows to set custom color, but only by providing hue value. According to android documentation:

(Hue) Value must be greater or equal to 0 and less than 360

If you know Hex or RGB value of your app theme, you need to do some calculations (see example ) or simply use some free online converter. In your case hue value will be 47.

Also, there is no need to set .icon() property in your code twice.

I have created this simple method to get marker of any color.

 public BitmapDescriptor getMarkerIcon(int color) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    return BitmapDescriptorFactory.defaultMarker(hsv[0]);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!