2
我試圖用CommonsWare's Example
定製片段&標題在圖形頁面視圖但是我不能夠自定義代碼片段的字樣。
運氣好嗎?使用自定義字樣在地圖V2
我試圖用CommonsWare's Example
定製片段&標題在圖形頁面視圖但是我不能夠自定義代碼片段的字樣。
運氣好嗎?使用自定義字樣在地圖V2
如果您從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);
}
}
我已經下來投給了以下原因,[Android不支持OTF ](http://stackoverflow.com/a/1430320/1008278)。在InfoWindowAdapter中不能識別'getAssets()'。我強烈建議您在回答之前確保您實施代碼,否則可能會誤導用戶。 – VenomVendor 2013-03-31 14:33:59
getAssets()是Context類的一個方法,它是PopupAdapters構造函數的參數。 Android支持OTF,但不支持1.0版本,甚至在鏈接中提供的更新中。我不是100%確定的,因爲OTF支持在Android中,但我的示例在運行4.2.2的Galaxy Nexus上運行。 – 2013-03-31 14:44:51
我已將您的代碼替換爲我的代碼,正在收到運行時錯誤。 – VenomVendor 2013-03-31 14:56:46