Wie die documentation heißt es:nicht auflösen kann Methode 'getFont (?)'
Android O lets you bundle fonts as resources by adding the font file in the res/font/ folder.
Als Ergebnis:
You can retrieve fonts by using the
getFont(int)
method, where you need to pass the resource identifier of the font that you want to retrieve. This method returns a Typeface object. This encodes the first of the weight or style variants of your font, if it is a font family. You can then use the Typeface.create(typeface, style) method to retrieve specific styles.Note: The TextView already does this for you.
Typeface typeface = getResources().getFont(R.font.myfont); textView.setTypeface(typeface);
Leider, wenn ich den obigen Code verwende ich die folgende Fehlermeldung erhalten:
cannot resolve method 'getFont(?)'
Früher verwendete ich folgendes zu tun:
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf");
Aber jetzt, wenn ich versuche, die Schriftarten Ordner in Vermögenswerte Ordner zu erstellen, springt er automatisch innerhalb res Ordner.
Ich benutze android studio 2.3. Vielen Dank im Voraus für jede Hilfe.
wie rufst du 'getFont'? Haben Sie ein gültiges 'Resources' Objekt? – njzk2
Sind Sie auf Entwicklervorschau ausgerichtet? – Submersed
@ njzk2 Ich weiß es nicht. Immer wenn ich versuche, den Schriftarten-Ordner im Ordner "Assets" zu erstellen, springt er aus dem Ordner und wechselt in den Ordner "res". – Darush