I want to use my own font for navigation drawer in android.I use the library comes with android studio according to this answer: https://stackoverflow.com/a/23632492/4393226. But I don't know how to change the font and make it RTL. I searched a lot and I found how to make the drawer RTL. I use this code:
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
and Android - Is Navigation Drawer from right hand side possible?
But as you know this only works in API 17 and above. Please help! How to change the menu font? How to make the layout RTL in right way?!
Edited: My font "TTF" file is in assets/fonts and I know how to set it for a textview using java, but I don't know how to set it to navigation drawer menu.
Adding to rischan's answer.
I edited 'mi' directly as those are my drawer menu titles. Then I changed the s.setSpan 1st parameter to use a custom class CustomTypefaceSpan.
CustomTypefaceSpan Class:
Can't believe how complicated it is just to change the fonts for the menu.
Thank you! I've successfully changed font on navigation drawer based on @Amir H post but with configuration (just add this several lines into your activity)
Maybe it will help someone :)
It Works For Fonts Only
First Of All Add color of your font (if you want to change) in
colors.xml
file located atres->values->colors.xml
likeThen edit
style.xml
file located at same values directory (there are two files edit that file which having your theme with stylename="your_theme"
or find line in that two fileHere we have to set font property. So you have to create new style tag in enclosing resource tags. in my case I create
Note that Name given for this tag is
MyText
. Now we have to use this name in aboved first style block whose name is your appication theme.Mentioned this new style in above appication theme style tag. In my case its like
Step 1:Make Style as follows in style.xml
Step 2: Add style as theme in your android.support.design.widget.NavigationView
android:theme="@style/NavigationView"
I found the answer: First create this class in your project:
Then add this method to your activity you want to change the font of navigation drawer menu:
and then add call the method you just added in your activity:
You can do this in more easy way...
First go in sytyle.xml and create there a new style.
and the second is go to your navigation xml code and put the item text appearance there.
now your final navigation code should be this.