Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font not applied to Material Design NavigationView menu items #50

Open
narun2001 opened this issue Jun 19, 2020 · 2 comments
Open

Font not applied to Material Design NavigationView menu items #50

narun2001 opened this issue Jun 19, 2020 · 2 comments

Comments

@narun2001
Copy link

Hi,
I have an issue similar to what is mentioned in issue #47 where the font I've set to use is not getting applied to the menu items in NavigationView. Just wondering if it's a known problem with Calligraphy as I couldn't see any response in that issue thread or the Exceptions section in the readme. Could you please help me with this?

Thanks,
Arun

@Stevemaster92
Copy link

Stevemaster92 commented Aug 12, 2020

As a workaround, try creating a custom style using fontFamily instead of fontPath and applying it directly to the NavigationView. For example,

styles.xml

<style name="TextAppearance.MenuItem" parent="android:TextAppearance">
    <item name="fontFamily">@font/[your-custom-font]</item>
</style>

activity_main.xml (layout file where your NavigationView resides)

...
<com.google.android.material.navigation.NavigationView
    android:id="@+id/side_nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:itemTextAppearance="@style/TextAppearance.MenuItem"
    app:menu="@menu/side_nav_main" />
...

Note: Do not forget to add your custom font file to the resource folder src/main/res/font in order to use @font!

@chrisjenx
Copy link
Member

The NavigationView creates Views instead of inflating them (dumb - google has a terrible habit of this). If it supports custom view you can inflate, that would be the easiest thing, as if there is no inflation there is no hook.

What we have done in the past in very hacky ways for things like Toolbar is we see if the class is that toolbar then manually interact with it by traversing it's tree.

If you want to throw up a PR to check if the class we are inflating is the NavMenu to do something similar please do and I'll try and get it released. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants