With the new NavigationView
, we are able to set a drawer's items through a menu resource in XML.
With that, we can set each item with something like
<item
android:id="@+id/drawer_my_account"
android:icon="@drawable/ic_my_account"
android:title="@string/drawer_my_account" />
But now, I want to set a custom typeface to each of those items in my drawer, and I could not find a way to do that, either by XML or by Java code. Is there a way to do it?
I really loved the solution of "Dragon who spits fire"'s but I didn't get the
textview
. This could be done by doing the following:design_navigation_item.xml:
style.xml:
attrs.xml:
It's a bit late to answer but I found a cleaner way to do it, so I would like to share.
Make a custom view
NavFontTextView.java
:Make a file called
CustomFontHelper.java
:Make a layout
layout/design_navigation_item.xml
(the name must be exactly the same):Place your font file
SourceSansPro-Bold.ttf
in this path:app/src/main/assets/fonts/SourceSansPro-Bold.ttf
You're good to go! This way, you can keep your main activity cleaner.
Here's a screenshot:
I have used app:theme
Styles.xml :
just add following class file to your project.
then create following method to your activity
and call it from activity.
and here is my output
this one working for me
res->values->styles
//to Set Custom Typeface MainApplication.java
// FontsOverride.java
Use the app:itemTextAppearance="" property. Hope this helps.
In styles.xml write