基于Hiren Patel解决方案。此代码创建一个TextView
从布局,而不是从零开始。一个显着的区别:如果您有clusters ,则在单击集群时不会看到void 标签。
override fun onMapReady(googleMap: GoogleMap) {
this.googleMap = googleMap
...
// Use this anonymous class or implement GoogleMap.InfoWindowAdapter.
googleMap.setInfoWindowAdapter(object : GoogleMap.InfoWindowAdapter {
override fun getInfoContents(marker: Marker): View? {
return null
}
override fun getInfoWindow(marker: Marker): View? =
if (marker.title == null)
null
else {
val inflater = LayoutInflater.from(context)
val view = inflater.inflate(R.layout.layout_marker, null, false)
view.label.text = marker.title
view
}
})
布局标记.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:textColor="$f0f0f0"
android:textSize="12sp"
tools:text="Marker"
android:background="#00aaee"
/>