Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use icons in navigation view's menu using icon font in android

I am trying to migrate my android application which is using the png assets to icon fonts. I could successfully use it in navigation drawer using a list view. But I couldn't use it in navigation view by specifying it in the xml file of the menu.

This is what I got when I tried with Navigation Drawer

When i tried with navigation drawer

I don't know how will I use icon fonts in navigation view to get those marked icons.

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav_apple"
        android:icon="@drawable/ic_menu_apple"
        android:title="Apple" />
    <item
        android:id="@+id/nav_chrome"
        android:icon="@drawable/ic_menu_chrome"
        android:title="Orange" />
    <item
        android:id="@+id/nav_left"
        android:icon="@drawable/ic_menu_left"
        android:title="Grapes" />
  </group>

How can I set those icons using icon font in this menu?

like image 421
Neeraj Avatar asked Feb 18 '16 08:02

Neeraj


1 Answers

You need to set textView.setTypeface where textView is item in your Navigation drawer. Also you need to have custom font with icons, put in to assets and then use it in code:

Typeface t = Typeface.createFromAsset(c.getAssets(), assetPath); textView.setTypeface(t);

like image 71
Volodymyr Avatar answered Oct 08 '22 19:10

Volodymyr