android - 使用 google maps api v2 的自定义信息窗口

标签 android google-maps-android-api-2

我可以用一个简单的代码块自定义 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 文本。我想将此默认信息窗口更改为透明的黑色矩形。我该怎么做?

enter image description here

最佳答案

您必须在 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/

相关文章:

android - 如何在android中更改placepicker的语言?

android - 评估项目 ':react-native-reanimated' 时出现问题

android - RecoverySystem.installPackage-/cache/recovery/command : open failed: EACCESS (permission denied) - missing permission after update Android to 4. 3+

android - 首次从 Android 市场安装 Android 应用程序时出现问题

android - 在 SQLite Android 中使用 ContentValues 和 Raw SQL 插入数据有什么区别?

java - 谷歌地图API v2在多个 fragment android

android - Google Map Android API v2 标记的错误标题

java - 非法状态异常 : Could not execute method for android:onClick when trying to migrate to another page?

Android Polyline - 逐点添加

android - 自定义 RecyclerViewAdapter 中的 MapView