Custom Infowindow Google Maps Android

Asked

Viewed 688 times

1

It is possible to customize an Infowindow of the marker in Googlemaps v2 from Android by placing clickable buttons, images, change background color etc?

If yes, how can I do that? Thanks if anyone has a tutorial on the subject

1 answer

1

And possible yes, there is this tutorial Markers and Listeners Google Maps that explains super well how to do and follows below an example.

map.setInfoWindowAdapter(new InfoWindowAdapter(){

@Override
public View getInfoWindow(Marker marker) {
    LinearLayout ll = new LinearLayout(MainActivity.this);
    ll.setPadding(20, 20, 20, 20);
    ll.setBackgroundColor(Color.GREEN);

    TextView tv = new TextView(MainActivity.this);
    tv.setText(Html.fromHtml("<b><font color=\"#ffffff\">"+marker.getTitle()+":</font></b> "+marker.getSnippet()));
    ll.addView(tv);

    Button bt = new Button(MainActivity.this);
    bt.setText("Botão");
    bt.setBackgroundColor(Color.RED);
    bt.setOnClickListener(new Button.OnClickListener(){

        @Override
        public void onClick(View v) {
            Log.i("Script", "Botão clicado");
        }

    });

    ll.addView(bt);

    return ll;
}   

});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.