[英]Google Maps Utils IconGenerator text styles and background
I just started using Google Maps Utils library so that I can have markers with text in them.我刚开始使用 Google Maps Utils 库,这样我就可以在其中添加带有文本的标记。 I understand the library so far and I'm successfully using it.
到目前为止,我了解该库并且我正在成功使用它。 Code snippet:
代码片段:
IconGenerator icnGenerator = new IconGenerator(this);
Bitmap iconBitmap = icnGenerator.makeIcon(item.placeItemName);
myPlaceItemMarkers.add(mMap.addMarker(new MarkerOptions().position(new LatLng(item.latitude, item.longitude))
.icon(BitmapDescriptorFactory.fromBitmap(iconBitmap)).anchor(0.5f, 0.6f)));
Now I started playing around with styling the window a bit and there are two functions that interest me in particular:现在我开始尝试设置窗口样式,有两个功能让我特别感兴趣:
icnGenerator.setBackground(Drawable background);
icnGenerator.setTextAppearance(int resid);
I looked up for info on docs and there's only info for BubbleIconFactory which is deprecated.我查找了有关文档的信息,但只有BubbleIconFactory的信息已被弃用。 Could someone tell me how to use these 2 functions?
有人能告诉我如何使用这两个功能吗? I know setTextAppearance is for changing text style but how do I do it?
我知道setTextAppearance用于更改文本样式,但我该怎么做? And if I'm not wrong setBackground is for setting custom marker background, but I don't know how to use that either.
如果我没有错的话setBackground是用于设置自定义标记背景,但我也不知道如何使用它。
I'm still not completely sure how to use setBackground() because I tried using Drawables but it wouldn't work but I figured out how to use setTextAppearance() .我仍然不完全确定如何使用setBackground()因为我尝试使用 Drawables 但它不起作用但我想出了如何使用setTextAppearance() 。
I just made a new style:我刚刚做了一个新样式:
<style name="iconGenText">
<item name="android:textSize">14sp</item>
<item name="android:textColor">#000000</item>
</style>
And then applied it to IconGenerator:然后将其应用到 IconGenerator:
IconGenerator icnGenerator = new IconGenerator(this);
icnGenerator.setTextAppearance(R.style.iconGenText);
It works as it should.它可以正常工作。
Set the background like this:像这样设置背景:
IconGenerator icnGenerator = new IconGenerator(this);
icnGenerator.setBackground(getResources().getDrawable(R.drawable.marker_background));
marker_background has to be a .9.png file. marker_background 必须是 .9.png 文件。 Like the drawables of the library .
就像图书馆的drawables一样。
It works pretty good for me.它对我来说效果很好。
if you're just wanting to change away from the default marker styling without getting fancy you can do this.如果你只是想改变默认标记样式而不喜欢你可以这样做。
icnGenerator.setStyle(IconGenerator.STYLE_BLUE)
There's currently 7 basic styles to select from:目前有 7 种基本样式可供选择:
IconGenerator.STYLE_BLUE
IconGenerator.STYLE_DEFAULT
IconGenerator.STYLE_GREEN
IconGenerator.STYLE_ORANGE
IconGenerator.STYLE_PURPLE
IconGenerator.STYLE_RED
IconGenerator.STYLE_WHITE
doc: https://www.javadoc.io/doc/com.google.maps.android/android-maps-utils/latest/com/google/maps/android/ui/IconGenerator.html文档: https : //www.javadoc.io/doc/com.google.maps.android/android-maps-utils/latest/com/google/maps/android/ui/IconGenerator.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.