Custom infowindow with google maps api v2

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

I can customize the content of the infoWindow with a simple block of code:

 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;          }     });  

But this changes only the content and not the infoWindow itself. It still stays white with a small shadow on the bottom and now a red HELLO text is visible with black bg. I want to change this default infoWindow to a transparent black rectangle. How can I do this?

回答1:

you have to write your code in getInfoWindow method. so you can customize info window. e.g.

@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; } 


回答2:

use this way...

myMap.setInfoWindowAdapter(new InfoWindowAdapter() {                  @Override                 public View getInfoWindow(Marker arg0) {                      ContextThemeWrapper cw = new ContextThemeWrapper(                             getApplicationContext(), R.style.Transparent);                     // AlertDialog.Builder b = new AlertDialog.Builder(cw);                     LayoutInflater inflater = (LayoutInflater) cw                             .getSystemService(LAYOUT_INFLATER_SERVICE);                     View layout = inflater.inflate(R.layout.custom_infowindow,                             null);                     return layout;                 }                  @Override                 public View getInfoContents(Marker arg0) {                      return null;                  }             }); 

R.style.Transparent add this in your style.xml

#00000000

Edited:

custom_infowindow.xml



回答3:

Try this...I have change little bit of your code.

Also change this...

 mMap.setInfoWindowAdapter(new InfoWindowAdapter() {          public View getInfoWindow(Marker arg0) {             View v = getLayoutInflater().inflate(R.layout.custom_infowindow, null);             return v;         }          public View getInfoContents(Marker arg0) {              //View v = getLayoutInflater().inflate(R.layout.custom_infowindow, null);              return null;          }     }); 

I hope it will work...:)



回答4:

You need to setInfoWindowAdapter() right after map.addMarker() method for this to take effect. Do not call setInfoWindowAdapter() in onMarkerClick().



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!