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

3

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?

Grumble answered 18/2, 2016 at 8:34 Comment(3)
Hope this link will help you code.tutsplus.com/tutorials/…Francophobe
@Francophobe 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.Grumble
I will check and let u knowFrancophobe
S
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);

Senter answered 18/2, 2016 at 10:37 Comment(1)
I'm trying to use my icon font in my navigation view's menu file, not in navigation drawer.Grumble
K
0

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

Koah answered 18/2, 2016 at 10:28 Comment(1)
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).Grumble
Q
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" >
Quorum answered 18/2, 2016 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.