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.
Android App Development for BeginnersStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to res/layout/nav_header_main.
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 findViewById(). Create a new Typeface from the specified font data. And at last setTypeface in text title.
You can do this in more easy way.
First go in style.xml and create there a new style.
<style name="RobotoTextViewStyle" parent="android:Widget.TextView"> <item name="android:fontFamily">@font/sans-serif-smallcaps</item> </style>
and the second is go to your navigation xml code and put the item text appearance there.
app:itemTextAppearance="@style/RobotoTextViewStyle"
now your final navigation code should be this.
<android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:itemTextAppearance="@style/RobotoTextViewStyle" android:fitsSystemWindows="true" app:headerLayout="@layout/nav_header_home" app:menu="@menu/activity_home_drawer" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With