Crash when using custom font for Toolbar

toolbar title custom font
font toolbar
how to set toolbar title font android
android toolbar set text font
android custom toolbar layout
android custom font
getsupportactionbar font
toolbar text style

In my activity, I have a custom toolbar. I'm trying to change its title font.

Previously, I was able to do that by putting the font in the asset folder. With Android Studio 3, we can now use fontFamily and FontsContract. I tried this approach through the code below:

mToolbar.setTitleTextAppearance(context,R.style.AppTheme_ActionBarText);

and the style

<style name="AppTheme.ActionBarText" parent="@android:style/Widget.ActionBar.TabText">
            <item name="fontFamily">@font/ultra</item>
        </style>

When I run the app, after a few seconds (the time it takes to download the custom font), the app crashes with the log below:

java.lang.NullPointerException: Attempt to read from field 'int android.support.v4.provider.FontsContractCompat$TypefaceResult.mResult' on a null object reference at android.support.v4.provider.FontsContractCompat$2.onReply(FontsContractCompat.java:277) at android.support.v4.provider.FontsContractCompat$2.onReply(FontsContractCompat.java:274) at android.support.v4.provider.FontsContractCompat$3.onReply(FontsContractCompat.java:312) at android.support.v4.provider.FontsContractCompat$3.onReply(FontsContractCompat.java:300) at android.support.v4.provider.SelfDestructiveThread$2$1.run(SelfDestructiveThread.java:149) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7225) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Is this a bug or is there a correct way to load the font via xml? I know another way is to load the font programmatically and use the listener to set the typeface on the text.

**EDIT: on the second application run, no crash happens (since the font was already downloaded). For testing purposes, I'm changing the font after every crash to debug...

Issue happen when user trying to start app with downloadable fonts when there isn't internet on device and this fonts wasn't downloaded previously. Then app will start, but crash will happen only after ~5-10 sech. I think when http timeout is happen.

So I haven't solution, therefore use xml-fonts instead of downloadable fonts, see https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html

FYI: all downloadable fonts loaded to /data/data/com.google.android.gms/files/fonts folder onto your devices, If you have rooted device, then it easy to delete and reproduce this issue more that one time.

android - Crash when using custom font for Toolbar, Issue happen when user trying to start app with downloadable fonts when there isn't internet on device and this fonts wasn't downloaded previously. Then app  I'm interested in using just text for the items in my toolbar. I am successfully seeing the text in the toolbar on top. Also, I have successfully loaded a custom font to be used on certain Buttons and Labels. I'm wondering if it's possible to use a custom font for the text button in the toolbar.

Edit: It appears the issue has been fixed as of version 27.1.0 of the support library.

This appears to be a support library issue. Google devs have indicated that the fix should be available after version 27.0.2, which is currently unreleased.

https://issuetracker.google.com/issues/69085400

AppCompat toolbar title font is not set · Issue #295 · chrisjenx , I am trying to style toolbar font, but nothing happens. I am using the latest calligraphy (2.2.0), appcompat (23.4.0), Android 6.0. You can apply a custom layout to the Title of the supportActionBar, as below: LEARNER-1446 - Fix crash in case of offline inline discussion view - New error design with text  In my activity, I have a custom toolbar. I'm trying to change its title font. Previously, I was able to do that by putting the font in the asset folder. With Android Studio 3, we can now use fontF

According to docs you should use app namespace when using Support Library 26:

When you declare font families in XML layout through the support library, use the app namespace.

So in your code:

    <item name="app:fontFamily">@font/ultra</item>

Toolbar miss layout when using Calligraphy · Issue #363 · chrisjenx , When using Calligraphy with global font configuration, we can reach for below miss to my custom font from Caligraphy, which causes this jumping/blinking. Fix a bug that caused the toolbar titles to jump in the first frame … actionbar vs toolbar toolbar tutorial in android actiobar tutorial in android implementation of toolbar as action bar. toolbar amdroid material design action bar. toolbar in android app how to use

This issue might happen when you run the application first time without any internet connection. Check your internet connection and try again.

How To Apply Custom Fonts To Views, FontUtils is a tiny font utility library used to apply custom fonts to Views. Toolbar​; NavigationView; Menu; Submenu; Other Views like EditText, Open your app level build.gradle file and add the following lines to About Us · Contact Us · Privacy Policy · Terms · Media Kit · Sitemap · Report a Bug · FAQ  Damaged fonts can cause various problems in Photoshop, some of which don't appear to be font-related. These solutions are listed in order of easiest, and most likely to locate the damaged font, to more challenging or time consuming. Important: Remove or update any third-party font plug-ins before

Adding custom "style" button to toolbar results in Word 2011 , Hi folks: I have been having lots of spinning-beachballs and crashing in Word 2011. advice here about removing duplicate fonts, removing templates, etc. with the new button added to the toolbar) will cause Word to crash  Custom fonts are built into Xamarin Forms, so I wouldn't think you'd need the SDK just to preview fonts. That being said, running my app using the SDK works fine and the font renders as expected! I added FontAwesome.otf to my Assets folder, then created the following simple little label:

Styling the Android Action Bar title using a custom typeface, You're likely running into some other bug. It's possible that some change in Android 4.4 is causing the font to not work properly, but it's not just  Custom fonts, means using a 3rd party font file (*.ttf) in your mobile app, instead of using any of the system defaults. As designers continue to wield more influence over the design of apps, custom fonts are an increasing necessity, especially since they want the app to look similar on multiple platforms.

38521, as part of the toolbar customization system, which is on the (event) horizon, this bug might get solved. users will be able to create custom toolbars and add  For that you have to create TextView and set the TypeFace(font) of your choice to that TextView and set it to the action bar as custom view. Checkout the below code for the same.

Comments
  • Is there any update on this. I am having the same issue.
  • Im facing same issue, @engincancan did you manage to solve it?
  • invalid cache and restart android studio.For me it worked. android studio - > File - > Invalid Cache / Restrat
  • This is what I already did long time ago, and it seems there still is no way to do it programmatically, so I'll mark it as solved in case others want to refer to it. Thanks.
  • In the styles.xml you can't really use app namespace, so to edit your above, just strip "app:". But still, the issue still was not resolved :/ It's something else, I edited my question