1

Custom info windowstutorialに設定しようとしています。ここでGoogleマップのカスタム情報ウィンドウを設定できません

は私のコードです:

public class MyActivity extends AppCompatActivity implements OnMapReadyCallback, ClickListenerChatFirebase, GoogleMap.InfoWindowAdapter { 

public void showMap() { 
     venueMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(venueLat), Double.parseDouble(venueLng))).title(venue.trim())); 
     venueMarker.showInfoWindow(); 
     getInfoWindow(venueMarker); 
    } 

public AcceptedRequest(LayoutInflater inflater){ 
     this.inflater = inflater; 
    } 

    @Override 
    public View getInfoWindow(Marker marker) { 

     // Getting view from the layout file 
//  inflater = getLayoutInflater(); 
     View v = inflater.inflate(R.layout.venue_infowindow_background, null); 

     TextView title = (TextView) v.findViewById(R.id.venue_txt); 
     title.setText(marker.getTitle()); 

     return v; 
    } 

    @Override 
    public View getInfoContents(Marker arg0) { 
     // TODO Auto-generated method stub 
     return null; 
    } 

} 

} 

ここvenue_infowindow_background.xmlです:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="horizontal" 
       android:background="@color/colorPrimary" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

    <TextView 
     android:id="@+id/venue_txt" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="venue" 
     android:textSize="14sp" 
     android:textStyle="bold" 
     android:textColor="@android:color/white"/> 

</LinearLayout> 

問題は何の変化が起こっていないと、情報ウィンドウはデフォルトのテキスト色と背景色を示しているということです。

この問題のお手伝いをしてください。

答えて

1

getInfoWindow()メソッドを直接呼び出すことはできません。

GoogleMap.InfoWindowAdapterインターフェイスを実装しているあなたのアクティビティにGoogleマップのInfoWindowAdapterを設定する必要があります。

このマーカーのために別のレイアウトを使用するためには
public void showMap() { 
    venueMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(venueLat), Double.parseDouble(venueLng))).title(venue.trim())); 
    venueMarker.showInfoWindow(); 

    //This won't work: 
    //getInfoWindow(venueMarker); 

    //Do this instead: 
    mMap.setInfoWindowAdapter(this); 
} 

、あなたは他のすべてのマーカーの異なるカスタムレイアウトを膨らませることができます:デフォルトのマーカーと「吹き出し」を使用するために

@Override 
public View getInfoWindow(Marker marker) { 
    View v = null; 
    if (marker.equals(venueMarker)) { 
     v = inflater.inflate(R.layout.venue_infowindow_background, null); 
    } else { 
     v = inflater.inflate(R.layout.some_other_layout, null); 
    } 

    TextView title = (TextView) v.findViewById(R.id.venue_txt); 
    title.setText(marker.getTitle()); 

    return v; 
} 

1つのカスタムマーカーではなく、getInfoWindow()をカスタムマーカーと共に使用し、getInfoContents()をデフォルトのマーカーとして使用することができます。 (詳細はhere)。このようなものが動作する可能性があります。:

@Override 
public View getInfoWindow(Marker marker) { 
    if (!marker.equals(venueMarker)) { 
     return null; 
    } 
    View v = inflater.inflate(R.layout.venue_infowindow_background, null); 
    TextView title = (TextView) v.findViewById(R.id.venue_txt); 
    title.setText(marker.getTitle()); 

    return v; 
} 

@Override 
public View getInfoContents(Marker arg0) { 
    if (marker.equals(venueMarker)) { 
     return null; 
    } 
    View v = inflater.inflate(R.layout.some_other_layout, null); 
    TextView title = (TextView) v.findViewById(R.id.venue_txt); 
    title.setText(marker.getTitle()); 

    return v; 
} 
+0

これは仕事をしましたが、すべてのマーカーの背景とテキストカラーを変更しました...どのように1つのマーカーに対して変更できますか? –

+0

'getInfoWindow()'オーバーライドを実装して、1つのマーカーのレイアウトを1つ増やし、他のすべてのマーカーのレイアウトを変更することができます。 –

+0

ですがどうですか?少し熟考してください。 –

関連する問題