Ressourcen zu Schriftarten
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Eine Schriftartressource definiert eine benutzerdefinierte Schriftart, die Sie in Ihrer App verwenden können. Schriftarten
Dabei kann es sich um einzelne Schriftartdateien oder eine Sammlung von Schriftartdateien,
und in XML definiert ist.
Weitere Informationen zum Definieren von Schriftarten
in XML oder verwende stattdessen herunterladbare Schriftarten.
Gruppierte Schriftart
Sie können Schriftarten als Ressourcen in einer App bündeln. Schriftarten werden in der
R
-Datei und sind automatisch als
. Sie können dann über die
Ressourcentyp font
.
- Dateispeicherort:
res/font/filename.ttf
(.ttf
, .ttc
, .otf
oder
.xml
)
Der Dateiname wird als Ressourcen-ID verwendet.
- Ressourcenreferenz:
- In XML:
@[package:]font/font_name
- Syntax:
-
<?xml version="1.0" encoding="utf-8"?>
<font-family>
<font
android:font="@[package:]font/font_to_include"
android:fontStyle=["normal" | "italic"]
android:fontWeight="weight_value" />
</font-family>
- Elemente:
-
<font-family>
- Erforderlich. Dies muss der Stammknoten sein.
Keine Attribute.
<font>
- Definiert eine einzelne Schriftart innerhalb einer Familie. Enthält keine untergeordneten Knoten.
Attribute:
android:fontStyle
- Keyword: Definiert den Schriftstil. Dieses Attribut ist
wird beim Laden der Schriftart in den Schriftartenstapel verwendet und überschreibt
alle Stilinformationen in den
Kopfzeilentabellen der Schriftart. Wenn Sie keine
das Attribut enthält, verwendet die App den Wert aus der
Headertabellen. Der konstante Wert ist entweder
normal
oder italic
.
android:fontWeight
- Ganzzahl. Die Stärke der Schrift. Dieses Attribut ist
wird beim Laden der Schriftart in den Schriftartenstapel verwendet und überschreibt
alle Schriftstärken in den
Kopfzeilentabellen der Schriftart. Die
Attributwert muss ein Vielfaches sein
100 zwischen 100 und 900 (einschließlich) liegt. Wenn Sie keine
das Attribut enthält, verwendet die App den Wert aus der Überschrift
Tabellen. Die häufigsten Werte sind 400 für ein reguläres Gewicht und 700
für Fettdruck.
- Beispiel:
- XML-Datei gespeichert unter
res/font/lobster.xml
:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/lobster_regular" />
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="@font/lobster_italic" />
</font-family>
XML-Datei, die in res/layout/
gespeichert ist und die die Schriftart auf eine
TextView
:
<?xml version="1.0" encoding="utf-8"?>
<EditText
android:fontFamily="@font/lobster"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World!" />
Herunterladbare Schriftart
In einer zum Download verfügbaren Schriftartressource wird eine benutzerdefinierte Schriftart definiert, die Sie in einer
Diese Schriftart ist in der App selbst nicht verfügbar. Stattdessen wird die Schriftart
die von einem
Schriftartanbieter abgerufen wurden.
- Dateispeicherort:
res/font/filename.xml
Der Dateiname ist die Ressourcen-ID.
- Ressourcenreferenz:
- In XML:
@[package:]font/font_name
- Syntax:
-
<?xml version="1.0" encoding="utf-8"?>
<font-family
android:fontProviderAuthority="authority"
android:fontProviderPackage="package"
android:fontProviderQuery="query"
android:fontProviderCerts="@[package:]array/array_resource" />
- Elemente:
-
<font-family>
- Erforderlich. Dies muss der Stammknoten sein.
Attribute:
android:fontProviderAuthority
- String. Erforderlich. Die Autorität der Schriftart
Anbieter, der die Schriftartanfrage definiert.
android:fontProviderPackage
- String. Erforderlich. Paketname der Schriftart
der für die Anfrage zu verwenden ist. Damit wird überprüft,
Identität des Anbieters.
android:fontProviderQuery
- String. Erforderlich. Die Zeichenfolgenabfrage der Schriftart.
Informationen zum Format dieser Schriftart finden Sie in der Dokumentation Ihres Schriftartanbieters.
.
android:fontProviderCerts
- Array-Ressource Erforderlich. Definiert die Gruppen von
Hashes für die Zertifikate, mit denen dieser Anbieter signiert wurde. Dies ist
wird zur Überprüfung der Identität des Anbieters verwendet und ist nur erforderlich
wenn der Anbieter nicht
im System-Image enthalten ist. Der Wert kann
auf eine einzelne Liste (eine String-Array-Ressource) oder eine Liste von Listen verweisen,
(Array-Ressource), wobei jede einzelne Liste für eine Ressource steht
Sammlung von Signatur-Hashes. Weitere Informationen finden Sie in der
Dokumentation zu diesen Werten.
- Beispiel:
- XML-Datei gespeichert unter
res/font/lobster.xml
:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
android:fontProviderAuthority="com.example.fontprovider.authority"
android:fontProviderPackage="com.example.fontprovider"
android:fontProviderQuery="Lobster"
android:fontProviderCerts="@array/certs">
</font-family>
XML-Datei, die in res/values/
gespeichert ist und das Zertifikatarray definiert:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="certs">
<item>MIIEqDCCA5CgAwIBAgIJA071MA0GCSqGSIb3DQEBBAUAMIGUMQsww...</item>
</string-array>
</resources>
XML-Datei, die in res/layout/
gespeichert ist und die die Schriftart auf eine
TextView
:
<?xml version="1.0" encoding="utf-8"?>
<EditText
android:fontFamily="@font/lobster"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World!" />
Alle Inhalte und Codebeispiele auf dieser Seite unterliegen den Lizenzen wie im Abschnitt Inhaltslizenz beschrieben. Java und OpenJDK sind Marken oder eingetragene Marken von Oracle und/oder seinen Tochtergesellschaften.
Zuletzt aktualisiert: 2025-07-27 (UTC).
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-07-27 (UTC)."],[],[],null,["# Font resources\n\nA font resource defines a custom font that you can use in your app. Fonts\ncan be individual font files or a collection of font files, known as a\nfont family and defined in XML.\n\nAlso see how to define [fonts\nin XML](/guide/topics/ui/look-and-feel/fonts-in-xml) or instead use [Downloadable Fonts](/guide/topics/ui/look-and-feel/downloadable-fonts).\n\nBundled font\n------------\n\n\nYou can bundle fonts as resources in an app. Fonts are compiled in the\n`R` file and are automatically available in the system as a\nresource. You can then access these fonts with the help of the\n`font` resource type.\n\nfile location:\n: `res/font/`*filename*`.ttf`\n (`.ttf`, `.ttc`, `.otf`, or\n `.xml`) \n\n The filename is used as the resource ID.\n\nresource reference:\n: In XML: `@[package:]font/`*font_name*\n\nsyntax:\n:\n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cfont-family\u003e\n \u003cfont\n android:font=\"@[package:]font/font_to_include\"\n android:fontStyle=[\"normal\" | \"italic\"]\n android:fontWeight=\"weight_value\" /\u003e\n \u003c/font-family\u003e\n ```\n\nelements:\n:\n\n `\u003cfont-family\u003e`\n : **Required.** This must be the root node.\n\n No attributes.\n\n `\u003cfont\u003e`\n\n : Defines a single font within a family. Contains no child nodes. Attributes:\n\n `android:fontStyle`\n : *Keyword* . Defines the font style. This attribute is\n used when the font is loaded into the font stack and overrides\n any style information in the font's header tables. If you don't\n specify the attribute, the app uses the value from the font's\n header tables. The constant value is either\n `normal` or `italic`.\n\n `android:fontWeight`\n : *Integer*. The weight of the font. This attribute is\n used when the font is loaded into the font stack and overrides\n any weight information in the font's header tables. The\n attribute value must be a multiple\n of 100 between 100 and 900, inclusive. If you don't specify\n the attribute, the app uses the value from the font's header\n tables. The most common values are 400 for regular weight and 700\n for bold weight.\n\nexample:\n : XML file saved at `res/font/lobster.xml`: \n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cfont-family xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n \u003cfont\n android:fontStyle=\"normal\"\n android:fontWeight=\"400\"\n android:font=\"@font/lobster_regular\" /\u003e\n \u003cfont\n android:fontStyle=\"italic\"\n android:fontWeight=\"400\"\n android:font=\"@font/lobster_italic\" /\u003e\n \u003c/font-family\u003e\n ```\n\n XML file saved in `res/layout/` that applies the font to a\n [TextView](/reference/android/widget/TextView):\n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cEditText\n android:fontFamily=\"@font/lobster\"\n android:layout_width=\"fill_parent\"\n android:layout_height=\"wrap_content\"\n android:text=\"Hello, World!\" /\u003e\n ```\n\nDownloadable font\n-----------------\n\n\nA downloadable font resource defines a custom font that you can use in an\napp. This font isn't available in the app itself. Instead, the font is\nretrieved from a font provider.\n\nfile location:\n: `res/font/`*filename*`.xml`\n The filename is the resource ID.\n\nresource reference:\n: In XML:`@[package:]font/`*font_name*\n\nsyntax:\n:\n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cfont-family\n android:fontProviderAuthority=\"authority\"\n android:fontProviderPackage=\"package\"\n android:fontProviderQuery=\"query\"\n android:fontProviderCerts=\"@[package:]array/array_resource\" /\u003e\n ```\n\nelements:\n:\n\n `\u003cfont-family\u003e`\n : **Required.** This must be the root node.\n\n attributes:\n\n `android:fontProviderAuthority`\n : *String* . **Required**. The authority of the font\n provider that defines the font request.\n\n `android:fontProviderPackage`\n : *String* . **Required**. The package name of the font\n provider to be used for the request. This is used to verify the\n identity of the provider.\n\n `android:fontProviderQuery`\n : *String* . **Required**. The string query of the font.\n Refer to your font provider's documentation on the format of this\n string.\n\n `android:fontProviderCerts`\n : *Array resource* . **Required**. Defines the sets of\n hashes for the certificates used to sign this provider. This is\n used to verify the identity of the provider and is only required\n if the provider isn't part of the system image. The value can\n point to a single list (a string array resource) or a list of lists\n (an array resource), where each individual list represents one\n collection of signature hashes. Refer to your font provider's\n documentation for these values.\n\n\nexample:\n : XML file saved at `res/font/lobster.xml`: \n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cfont-family xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:fontProviderAuthority=\"com.example.fontprovider.authority\"\n android:fontProviderPackage=\"com.example.fontprovider\"\n android:fontProviderQuery=\"Lobster\"\n android:fontProviderCerts=\"@array/certs\"\u003e\n \u003c/font-family\u003e\n ```\n\n XML file saved in `res/values/` that defines the cert array:\n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cresources\u003e\n \u003cstring-array name=\"certs\"\u003e\n \u003citem\u003eMIIEqDCCA5CgAwIBAgIJA071MA0GCSqGSIb3DQEBBAUAMIGUMQsww...\u003c/item\u003e\n \u003c/string-array\u003e\n \u003c/resources\u003e\n ```\n\n XML file saved in `res/layout/` that applies the font to a\n [TextView](/reference/android/widget/TextView):\n\n ```xml\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cEditText\n android:fontFamily=\"@font/lobster\"\n android:layout_width=\"fill_parent\"\n android:layout_height=\"wrap_content\"\n android:text=\"Hello, World!\" /\u003e\n ```"]]