Gaëtan
Gaëtan

Reputation: 12552

Apply application-wide custom font on Android

I am trying to use Android Oreo custom font feature in my application. It works fine if I set the font manually on each TextView, but when trying to set it globally in my application theme, it has some issues.

My theme looks like this:

<style name="MyTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <!-- Other attributes -->
    <item name="fontFamily">@font/custom_font</item>
</style>

The font is correctly applied in the BottomNavigationView and the Buttons, but not in the Toolbar or TextView with a style (like Body1).

Is there a simple way to set a custom font on the whole application? Do I have to override each style to add the fontFamilly attribute?

Update: I was using the style attribute to set my text appearance, instead of android:textAppearance. Using the later fixed most of my issues with custom font. Now, only the Toolbar is still using the default font.

Upvotes: 1

Views: 188

Answers (2)

Tony Lin
Tony Lin

Reputation: 805

I don't think there is a way to apply font application wide, but activity wide is possible.

Checkout this Calligraphy, it works like a charm.

Upvotes: 1

Related Questions