Monday, July 18, 2016

Android Google Map Multiple Line Snippet on Info Window


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

 @Override
 public View getInfoWindow(Marker arg0) {
  return null;
 }

 @Override
 public View getInfoContents(Marker marker) {

  Context context = getApplicationContext(); //or getActivity(), YourActivity.this, etc.

  LinearLayout info = new LinearLayout(context);
  info.setOrientation(LinearLayout.VERTICAL);

  TextView title = new TextView(context);
  title.setTextColor(Color.BLACK);
  title.setGravity(Gravity.CENTER);
  title.setTypeface(null, Typeface.BOLD);
  title.setText(marker.getTitle());

  TextView snippet = new TextView(context);
  snippet.setTextColor(Color.GRAY);
  snippet.setText(marker.getSnippet());

  info.addView(title);
  info.addView(snippet);

  return info;
 }
});

No comments:

Post a Comment