6

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?

SMR
  • 6,628
  • 2
  • 35
  • 56
Neeraj
  • 1,769
  • 3
  • 24
  • 41
  • Hope this link will help you http://code.tutsplus.com/tutorials/how-to-use-fontawesome-in-an-android-app--cms-24167 – Rahul Feb 18 '16 at 09:26
  • @Rahul It says how to use font icons in android. The thing is that I need to use them in navigation view menu. The menu item needs a `textview` in order do so. – Neeraj Feb 18 '16 at 09:39
  • I will check and let u know – Rahul Feb 18 '16 at 09:55

3 Answers3

1

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

Volodymyr
  • 6,393
  • 4
  • 53
  • 84
  • I'm trying to use my icon font in my navigation view's menu file, not in navigation drawer. – Neeraj Feb 18 '16 at 10:59
0

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

Mahdi Astanei
  • 1,905
  • 1
  • 17
  • 30
  • But the menu layout of navigation view doesn't have a text view. All it has got is the title and the icon (which i suppose is a imageview). – Neeraj Feb 18 '16 at 11:03
0
<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" >
Android Geek
  • 8,956
  • 2
  • 21
  • 35