Google Maps:您可以将代码段内的字符串设置为粗体吗? [英] Google maps: can you make string inside snippet bold?

查看:92
本文介绍了Google Maps:您可以将代码段内的字符串设置为粗体吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直试图创建一个显示传感器数据的自定义信息窗口.以前我的问题是我从未解决过如何为不同标记创建不同的信息窗口.所有标记信息窗口均已使用新数据进行了更新.

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.

我的代码看起来像

    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.

谢谢.

编辑使用自定义信息窗口进行了尝试.这样一来,当我获得新数据时,所有标记信息窗口都将更新.

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;

        }
    });


}

推荐答案

您可以创建自己的自定义信息窗口并设置内容样式.

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

这篇关于Google Maps:您可以将代码段内的字符串设置为粗体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆