我正在尝试使用 CommonsWare's Example 自定义 MapView 中的 fragment 和标题的 View
但是,我无法自定义代码段的字体。
有运气吗?
最佳答案
如果您扩展了 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/