Essential Android Custom Fonts edit forum

Working with fonts in Android O

Android O changes the way to work with fonts.

Android O introduces a new feature, called Fonts in XML, which allows you to use fonts as resources. This means, that there is no need to bundle fonts as assets. Fonts are now compiled in an R file and are automatically available in the system as a resource.

In order to add a new font, you have to do the following:

You can also create your own font family by adding the following XML file into the res/font directory:

<?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>

You can use both the font file and the font family file in the same way:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/myfont"/>

Or like this:

<style name="customfontstyle" parent="@android:style/TextAppearance.Small">
    <item name="android:fontFamily">@font/myfont</item>
</style>
Typeface typeface = getResources().getFont(R.font.myfont);
textView.setTypeface(typeface);

Table Of Contents
39 ACRA
64 Menu
86 Custom Fonts
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close