I'm unable to set the custom font in my style file.
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="android:textViewStyle">@style/fontTextView</item>
...
</style>
<style name="fontTextView" parent="@android:style/Widget.TextView">
<item name="android:fontFamily">@font/example</item>
</style>
</resources>
and I still see default font in my app. But when I change fontFamily
to one of the default ones, then it changes
<style name="fontTextView" parent="@android:style/Widget.TextView">
<item name="android:fontFamily">monospace</item>
</style>
It also works if I set my custom font programmatically.
setTypeface(ResourcesCompat.getFont(context, R.font.example));
How to make it works for my custom font in styles.xml
?
I set compiltSdkVersion
to 26
and buildToolsVersion
to 26.0.2
. Also I'm using support library:
def supportVersion = '26.1.0'
implementation "com.android.support:appcompat-v7:$supportVersion"
My font family:
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/example_regular"
app:fontStyle="normal"
app:fontWeight="300"
app:font="@font/example_regular"/>
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/example_regular"
app:fontStyle="normal"
app:fontWeight="400"
app:font="@font/example_regular"/>
<font
android:fontStyle="normal"
android:fontWeight="400"
android:font="@font/example_regular"
app:fontStyle="normal"
app:fontWeight="700"
app:font="@font/example_regular"/>
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="@font/example_regular"
app:fontStyle="italic"
app:fontWeight="300"
app:font="@font/example_regular" />
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="@font/example_regular"
app:fontStyle="italic"
app:fontWeight="400"
app:font="@font/example_regular" />
<font
android:fontStyle="italic"
android:fontWeight="400"
android:font="@font/example_regular"
app:fontStyle="italic"
app:fontWeight="700"
app:font="@font/example_regular" />
</font-family>
I Use the same *ttf
file for test purpose.