Создайте каталог шрифтов в папке ресурсов и вставьте файл шрифта ttf. Затем создайте ресурс шрифта 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/roboto_light" />
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="@font/roboto_light_italic" />
</font-family>
Теперь вы можете применить шрифт, как показано ниже. Также обратите внимание на атрибут 'textStyle'
<TextView
android:textStyle="italic"
android:fontFamily="@font/family_roboto_light"
android:textColor="@color/primaryTextColor"
android:textSize="20sp"
android:gravity="center"
android:id="@+id/textView36"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Internet connection" />
<TextView
android:fontFamily="@font/family_roboto_light"
android:textStyle="normal"
android:textSize="20sp"
android:gravity="center"
android:id="@+id/textView37"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No Internet connection" />
Если вы хотите сделать из кода, используйте следующий, но минимальный уровень API 26
Typeface typeface = getResources().getFont(R.font. roboto_light_italic);
textView.setTypeface(typeface);
Библиотека поддержки 26.0 обеспечивает поддержку функции «Шрифты в XML» на устройствах под управлением Android 4.1 (уровень API 16) и выше.
Typeface typeface = ResourcesCompat.getFont(context, R.font. roboto_light_italic);