Calligraphy: Calligraphy does not work with NavigationView

I tried to change it using Calligraphy configs but didn’t work CalligraphyConfig.initDefault(new CalligraphyConfig.Builder() .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf") .setFontAttrId(R.attr.fontPath) .build());

Also, I tried to get the menu from the NavigationView navigationView.getMenu() and use CalligraphyTypefaceSpan to set the title with no luck!

Is there anyway to achieve that?

Thanks in advance

About this issue

  • Original URL
  • State: open
  • Created 8 years ago
  • Reactions: 4
  • Comments: 21 (7 by maintainers)

Most upvoted comments

I ended-up hacking the drawer menu to force the font when the DrawerStateChanged: See the source code here:

https://gist.github.com/jzeferino/797c5e6b72c666b6f87969f6146a2a6e

@jzeferino Great tip! But, i realized that when the activity is resumed or when configuration changes, it uses the default font. In that case, it work when close and reopen the navigationview (eg. when the app is restarted or something related to configuration change while nav-view its opened).

Finally, i ended up using this approach:

(1) in strings.xml:

    <style name="AppTheme.NavigationView">
        <item name="android:textSize">16sp</item>
        <item name="fontPath">fonts/Custom-font.ttf</item>
    </style>

(2) in activity_home.xml:

<android.support.design.widget.NavigationView
        android:id="@+id/home_navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:theme="@style/AppTheme.NavigationView"
        app:menu="@menu/menu_drawer" />

Taken from here

I have custom font with calligraphy working a-ok with <android.support.design.widget.NavigationView /> I wonder if there’s an issue with app:itemTextAppearance="@style/AppTheme.NavigationView"? I am not using that, instead app:itemTextColor="@color/textColorBright". I’ve found with other android.support.design views the TextAppearance screws things up.

I think the NavigationView isn’t a textview. and doesn’t inflate it’s children.

Need to nudge Goog to make there support lib stuff use the LayoutInflater.