我可以用一个简单的代码块自定义 infoWindow 的内容:
private GoogleMap mMap;
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker arg0) {
View v = getLayoutInflater().inflate(R.layout.custom_infowindow, null);
return v;
}
});
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#55000000" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELLO"
android:textColor="#FF0000"/>
</LinearLayout>
但这只会改变内容,不会改变 infoWindow 本身。它仍然保持白色,底部有一个小阴影,现在可以看到带有黑色背景的红色 HELLO 文本。我想将此默认信息窗口更改为透明的黑色矩形。我该怎么做?
最佳答案
您必须在 getInfoWindow 方法中编写代码。这样您就可以自定义信息窗口。 例如
@Override
public View getInfoWindow(Marker marker) {
// Getting view from the layout file
View v = inflater.inflate(R.layout.map_popup, null);
TextView title = (TextView) v.findViewById(R.id.title);
title.setText(marker.getTitle());
TextView address = (TextView) v.findViewById(R.id.distance);
address.setText(marker.getSnippet());
return v;
}
@Override
public View getInfoContents(Marker arg0) {
// TODO Auto-generated method stub
return null;
}
关于android - 使用 google maps api v2 的自定义信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16317224/