android - 在 Maps V2 中使用自定义字体

标签 android textview infowindow android-maps-v2

我正在尝试使用 CommonsWare's Example 自定义 MapView 中的 fragment 和标题的 View
但是,我无法自定义代码段的字体
Custom Snippet MapsV2
有运气吗?

最佳答案

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

我已经扩展了 PopupAdapter 以从我的 Assets 文件夹加载字体,并将其设置为标题和 fragment View 字体

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

关于android - 在 Maps V2 中使用自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15668430/

相关文章:

swift - 如何在 UITableVIew 的不同单元格中使用 UITextView 获取用户输入

php - 谷歌地图标记加载最后一条记录

javascript - 谷歌地图 - 具有独特信息窗口的多个标记

angularjs - 标记仅显示 JSON 数组中的最后一个元素

java - 我应该为每个 Activity 实例化一个新的 Facebook 变量,还是使用静态 Facebook 变量

android - 使用流通过套接字发送和接收字符串和文件

android - Android 中的 Gstreamer。 UDP流

android - 应用程序关闭时推送通知不起作用

android - TextView 未在 1 行中显示全文 - Android

android - Kotlin:如何使用 Kotlin 在 Android 中获取和设置文本到 TextView?