How to Change the Text Font of Side Navigation Drawer Items in Android? - GeeksforGeeks

06 Jan, 2021
The navigation drawer is the most common feature offered by android and the navigation drawer is a UI panel that shows your app’s main navigation menu. It is also one of the important UI elements, which provides actions preferable to the users like example changing user profile, changing settings of the application, etc. The user can view the navigation drawer when the user swipes a finger from the left edge of the activity. They can also find it from the home activity by tapping the app icon in the action bar. The drawer icon is displayed on all top-level destinations that use a DrawerLayout. Have a look at the following image to get an idea about the Navigation drawer.
In this article, we will see how we change the text font of the navigation drawer’s item. Before starting we need to create a project with Side Navigation Drawer. 
Method 1: Create a new project from the file option in the left corner. Go to the File > New > New Project and Select the Navigation Drawer Activity option and enter the project name. Let the remaining things be as it is.
Method 2: You can create a side navigation drawer manually. To do so click here Navigation Drawer in Android.
Step 1: Go to the app > res > values > themes > themes.xml file and write down the flowing code inside the <resources> tag.
XML
<!--new style is created here--><style name="NewFontStyle" parent="android:Widget.TextView">  <item name="android:fontFamily">sans-serif-smallcaps</item></style>
Step 2: Open activity_main.xml file and go to NavigationView tag and set the style in itemTextAppearance attribute. 
app:itemTextAppearance=”@style/NewFontStyle”
Below is the complete code for the activity_main.xml file.
XML
<?xml version="1.0" encoding="utf-8"?><androidx.drawerlayout.widget.DrawerLayout     xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/drawer_layout"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:fitsSystemWindows="true"    tools:openDrawer="start">      <include        layout="@layout/app_bar_main"        android:layout_width="match_parent"        android:layout_height="match_parent" />      <com.google.android.material.navigation.NavigationView        android:id="@+id/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/NewFontStyle"        app:menu="@menu/activity_main_drawer" />      </androidx.drawerlayout.widget.DrawerLayout>
Before:
After:
android
Android
Android
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Resource Raw Folder in Android Studio
Flutter - Custom Bottom Navigation Bar
How to Read Data from SQLite Database in Android?
How to Post Data to API using Retrofit in Android?
Retrofit with Kotlin Coroutine in Android
How to Get Current Location in Android?
Android Listview in Java with Example
Flexbox-Layout in Android
How to Save Data to the Firebase Realtime Database in Android?
How to Change the Background Color After Clicking the Button in Android?