2013-03-27 2 views

ответ

4

Если вы распространили пример из CommonsWare, у вас должен быть PopupAdapter, который отвечает за отображение вашего InfoWindow.

я расширил, что PopupAdapter загрузить Typeface из папки моих активов, и установить его в качестве заголовка и фрагмент Просмотров шрифта

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

Я вниз проголосовал по следующим причинам [Android не поддерживает OTF ] (http://stackoverflow.com/a/1430320/1008278). 'getAssets()' не распознается в 'InfoWindowAdapter'. Я настоятельно рекомендую вам убедиться, что вы реализуете код перед ответом, cox, он может ввести пользователей в заблуждение. – VenomVendor

+1

getAssets() - это метод класса Context, который является параметром конструктора PopupAdapters. Android поддерживает otf, но не с версии 1.0, даже в обновлении, указанном в вашей ссылке. Я не уверен на 100%, так как поддержка OTF в Android, но мой пример работает на Galaxy Nexus с 4.2.2. –

+0

Я заменил свой код кодом, я получаю ошибку времени выполнения. – VenomVendor

Смежные вопросы