Neeraj
Neeraj

Reputation: 1817

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?

Upvotes: 6

Views: 1589

Answers (3)

Android Geek
Android Geek

Reputation: 9225

<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="@drawable/bg_all"

app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:theme="@style/list_item_appearance"
app:menu="@menu/drawer_menu" >

Upvotes: 0

Volodymyr
Volodymyr

Reputation: 6569

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);

Upvotes: 1

Mahdi Astanei
Mahdi Astanei

Reputation: 1905

Im not sure but You can use Textview instance of item and set typeface in java to it.

Upvotes: 0

Related Questions