question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AppCompat toolbar title font is not set

See original GitHub issue

Hi! I am trying to style toolbar font, but nothing happens. I am able to set font color and style, but not the font itself. I am using the latest calligraphy (2.2.0), appcompat (23.4.0), Android 6.0.

<android.support.v7.widget.Toolbar
        android:id="@+id/main_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        app:title="@string/app_name"
        app:titleTextAppearance="@style/DancingWhite"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>

...

<style name="DancingWhite" parent="android:TextAppearance">
        <item name="android:textSize">22sp</item>
        <item name="android:textColor">@color/colorTitle</item>
        <item name="android:textStyle">italic</item>
        <item name="fontPath">fonts/DancingScript-Regular.otf</item>
    </style>

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:23 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
AnoDestcommented, May 15, 2017

The problem is that Toolbar creates TextViews for title and subtitle programmatically inside itself. It means that it doesn’t use wrapped LayoutInflater by Calligraphy. Instead it uses system Typefaces depending on fontFamily and fontStyle from textAppearence attribute.

But Calligraphy listens for GlobalLayout changes and tries to load style from theme.

So what I’ve done: Add activity theme and customize ActionBarStyle:

<style name="ActivityTheme" parent="AppTheme.Base">
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>

<style name="ActionBarStyle" parent="Widget.AppCompat.Light.ActionBar.Solid">
        <item name="android:titleTextStyle">@style/ToolbarTitleTextAppearance</item>
</style>

<style name="ToolbarTitleTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textSize">20sp</item>
        <item name="fontPath">fonts/Roboto-Medium.ttf</item>
</style>
3reactions
max-pfeiffercommented, Feb 8, 2017

+1 here: using calligraphy:2.2.0, appcompat-v7:25.1.1

Everything is set on the toolbar title from the style (color, size) except the font. And I added the attachBaseContext override in the activity.

    <style name="ToolbarTitleTextAppearance" parent="android:TextAppearance">
        <item name="android:textColor">@android:color/white</item>
        <item name="android:textSize">22sp</item>
        <item name="fontPath">fonts/Roboto-Light.ttf</item>
    </style>

        <android.support.v7.widget.Toolbar
            android:id="@+id/activity_listview_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:elevation="4dp"
            app:titleTextAppearance="@style/ToolbarTitleTextAppearance"/>
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set a custom font to the title in toolbar android
Select the option of fontFamily and select the font you want under the given options. If it is not given, you can search...
Read more >
How to Change Font of Toolbar Title in an Android App?
First, add a font file in the src/main/assets/fonts/ of your project. Then create variables for Toolbar and text title and call the method ......
Read more >
Change Toolbar Font-Family in Android. | by Danish Amjad
Change Font for Toolbar. Now, In Android, we often need to change the font-family for Toolbar as well to look more appealing UI...
Read more >
Toolbar - Android Developers
Toolbar supports a more focused feature set than ActionBar. ... android:accessibilityHeading, Whether or not this view is a heading for accessibility ...
Read more >
Android Appcompat Toolbar Title Not Shown Correctly
This page shows Java code examples of androidx.appcompat.widget. Sets the font of any TextView found within the ToolBar. when this issue gets resolved:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found