Open In App

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

Last Updated : 06 Jan, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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.

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 by Step Implementation

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: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>


Output UI:

Before:

After:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads