Fonts in XML android:fontFamily is not applied to toolbars

download fonts for android studio
android set font family programmatically
android use custom font in xml
android custom font textview
android font family list
apply font programmatically android
typeface android
android custom font style xml

I'm using the new Fonts in XML feature, which was introduced in Android 8.0 Oreo with the Support Library 26.1.0. The default font family for the whole application is applied by setting the android:fontFamily attribute inside the application theme:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
     ...
    <item name="android:fontFamily">@font/proxima_nova</item>
</style>

The font is properly applied to all views in the app except Toolbar. All toolbars keep using the Roboto font:

UPDATE: The issue seems to be fixed in Support Library 27.0.0. I cannot reproduce it any longer.

I've not yet tested on all Android version but this seems to work:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
     ...
    <item name="android:fontFamily">@font/proxima_nova</item>
    <item name="toolbarStyle">@style/AppTheme.Toolbar</item>
</style>

<style name="AppTheme.Toolbar" parent="Widget.AppCompat.Toolbar">
    <item name="titleTextAppearance">@style/AppTheme.ToolbarTextStyle</item>
</style>

<style name="AppTheme.ToolbarTextStyle" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:fontFamily">@font/proxima_nova</item>
    <item name="fontFamily">@font/proxima_nova</item>
</style>

How to Change Fonts on Your Android Device Without Rooting, How can I install fonts on my android without root? A quick search on our beloved-yet-fickle Stack Overflow yields a handful of strategies for changing the font of the Toolbar. Top solutions include defining a custom Toolbar layout, setting text…

I used this util method to set titles with different fonts to the action bar:

public static CharSequence createSpannableActionBarTitle(Context context, CharSequence title) {
    SpannableString spannedTitle = new SpannableString(title);

    int titleColor = context.getResources().getColor(R.color.white);
    spannedTitle.setSpan(new ForegroundColorSpan(titleColor), 0, spannedTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spannedTitle.setSpan(new TypefaceSpan(context, R.string.Roboto_Medium), 0, spannedTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannedTitle;
}

How to change the Font Size in a whole Application , How do I change the font size on an entire Android app? Declaring fonts in XML and using them in XML layouts is great. However, there are certain situations where you might have to apply fonts programmatically in order to use them in certain UI elements. An example of this is using styled text in a Toolbar .

I spent quite a while to figure this out (even with Support Library 27.1.0). So, here's my solution to this:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:fontFamily">@font/proxima_nova</item> <!-- Default app font -->
    <item name="actionBarStyle">@style/Custom.ActionBar</item>
</style>

<style name="Custom.ActionBar" parent="Widget.AppCompat.ActionBar">
    <item name="background">@color/colorPrimary</item>
    <item name="titleTextStyle">@style/Custom.ActionBar.Title</item>
</style>

<style name="Custom.ActionBar.Title" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:fontFamily">@font/proxima_nova_bold</item>
</style>

As you can see, instead of referencing Toolbar, I got it to work by referencing ActionBar instead. With the above, the default font for the whole app is Proxima Nova (Regular), while the Toolbar/Action Bar is set to Proxima Nova Bold.

Some context: For the life of me, I could not get custom font to work using a font xml (where you should set the normal & italic font for regular & bold). So, the @font/proxima_nova_bold in the code links to the font file itself, res/font/proxima_nova_bold.ttf, which works fine.

How to change the Toolbar font on Android - Livefront, and . 50 would make it half. Call setTextSize() on all of your views and layout texts on the screen. The catch here is that the android:fontFamily attribute is not available for API levels below API 16, while we’re trying to backport this feature all the way to API 14. To go around this, gotcha, we can use the app namespace instead. However, there seems to be another interesting discovery:

If u r using fonts as usual

Make sure the activity extends AppCompatActivity

My fonts could not be rendered when my activity extended Activity.

How to Use Custom Fonts as Resources in Android Studio (Incl , font of the Toolbar. Top solutions include defining a custom Toolbar layout, setting text… AppCompat.Light"> <item name="android:fontFamily">@font/​pacifico</item> Use android:theme NOT style --> <android.support.v7.widget.​Toolbar Then create a new XML file in the font folder for the font family. The name of the XML file has no affinity or relationship to the fonts being referenced; the resource file can be any legal Android resource file name. This XML file will have a root font-family element that contains one or more font elements.

Using Fonts in Android, By adding the fontFamily attribute to the AppTheme instead of a single TextView, we can apply Duration: 16:54 Posted: Apr 16, 2019 Downloadable Fonts allow the ability for apps to request fonts from a font provider application instead of including font files in the apk or downloading it themselves. A font provider application retrieves fonts and caches them locally so that other apps can request and share fonts.

Can't change Toolbar's font from default. · Issue #181 · chrisjenx , Android O and Support Library 26 introduce new ways of working with asset in XML layouts Duration: 3:30 Posted: Sep 12, 2017 hi, i'm working on a project in xamarin android using visual studio 2015, how can i use custom fonts in the application. This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use.

AppCompat toolbar title font is not set · Issue #295 · chrisjenx , I have a problem with changing the Toolbar's title font. It successfully gets the default font set in Application, but no way to configure it separately. I tried all ActionBar.Title"> <item name="android:textSize">18sp</item> <item I used the layout solution and applied fontPath to the TextView . I also had to  Custom Fonts on Labels. To apply the new font to labels (or any other control that supports the FontFamily property), simply specify the name of the font family. Please note, the name of the font family is not the same as the filename. If you don’t know the name, you can find out a few different ways.

Comments
  • Thanks, it might be a workaround, but the final goal is to have all views styled without need for manual styling. I've created a ticket in Google Issue Tracker: issuetracker.google.com/issues/68308866.
  • I think the android:fontFamily in AppTheme is causing the toolbar to change instead of toolbarStyle. I used this code without the default font under AppTheme & it doesn't style the toolbar text.
  • @Aba did you find any solution?
  • Hi @Jorge. Yes, I've added my solution as an answer.