2

我正在尝试使用CommonsWare 的示例
在 MapView 中自定义片段和标题的视图但是我无法自定义片段的字体
自定义片段 MapsV2
运气好的话?

4

1 回答 1

4

如果你从 CommonsWare 扩展了这个例子,你应该有一个 PopupAdapter 负责显示你的 InfoWindow。

我已经扩展了 PopupAdapter 以从我的资产文件夹中加载字体,并将其设置为标题和片段视图字体

class PopupAdapter implements InfoWindowAdapter {
    LayoutInflater inflater = null;

    // Context is most likely the map hosting activity. 
    // We need this so we get access to the Asset Manager
    Context context = null;

    PopupAdapter(LayoutInflater inflater, Context context) {
        this.inflater = inflater;
        this.context = context;
    }

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

    @Override
    public View getInfoContents(Marker marker) {
        View popup = inflater.inflate(R.layout.popup, null);

        TextView tv = (TextView) popup.findViewById(R.id.title);

        tv.setText(marker.getTitle());

        // We load a typeface by using the static createFromAssets method
        // and provide the asset manager 
        // and a path to the file within the assets folder
        Typeface tf = Typeface.createFromAsset(context.getAssets(),
                "GoodDog.otf");
        // then set the TextViews typeface
        tv.setTypeface(tf);
        tv = (TextView) popup.findViewById(R.id.snippet);
        tv.setText(marker.getSnippet());
        tv.setTypeface(tf);

        return (popup);
    }
}
于 2013-03-31T14:13:43.467 回答