Google maps: can you make string inside snippet bold?

落爺英雄遲暮 提交于 2019-12-25 09:03:49

问题


I have for a while been trying to make a custom info window that shows sensor data. My problem before was that I never solved how to make different info windows for different markers. All markers info windows were updated with the new data.

So in order to get around this problem I was thinking about using the original info window.

My code looks like

    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("co: " +String.valueOf(co_mV) + " mV");
    markerOptions.snippet("no2: " + String.valueOf(co_mV) + " mV");

Is it possible to make the snippet bold or title not bold without creating your own info window? Because this would solve my problem.

Thanks.

EDIT Tried using custom info windwow. This made it so that all markers info windows were updated when I got new data.

protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
    mGoogleApiClient.connect();

    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        public View getInfoWindow(Marker arg0) {
            View v = getLayoutInflater().inflate(R.layout.custom_infowindow, null);
            TextView tv = (TextView) v.findViewById(R.id.infoText);
            tv.setText("CO2 data: "+String.valueOf(co_mV) + "mV" +"\n" + "N2 data: "+String.valueOf(no2_mV) +" mV");

            return v;
        }

        public View getInfoContents(Marker arg0) {


            return null;

        }
    });


}

回答1:


You can create your own custom info window and style the contents.

custom_info.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#fff"
android:padding="10dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
    android:textColor="@color/black"
    android:id="@+id/title"
    android:textStyle="bold"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
    <TextView
    android:textColor="@color/black"
    android:id="@+id/snippet"
    android:textStyle="bold"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
</LinearLayout>

and then creating the custom info window as below

googlemap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
        View v = getLayoutInflater().inflate(R.layout.custom_info, null);
        TextView title= (TextView) v.findViewById(R.id.title);
        TextView snippet= (TextView) v.findViewById(R.id.snippet);
        title.setText("your value");
        snippet.setText("your value");
        return v;
        }
@Override
public View getInfoContents(Marker arg0) {
        return  null;

        }
        });

markerOptions.showInfoWindow();


来源:https://stackoverflow.com/questions/43374214/google-maps-can-you-make-string-inside-snippet-bold

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