Colored Icons In NavigationView

10,851

Solution 1

Yes you can add colored icon using menu group items:

<item
        android:id="@+id/drawer_artist"
        android:icon="@drawable/artist"
        android:title="Artists"/>

And for highlighting the selcted item Use the code below for default selection:

navigationView.getMenu().getItem(0).setChecked(true);

And You can select(highlight) the item by calling

onNavigationItemSelected(navigationView.getMenu().getItem(0));

Edit

If you are using navigationview you can edit option for changing the colortint of icons as follows:

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

Edit

If you set navigationView.setItemIconTintList(null); you will get colored icons.

Solution 2

You can set it in your Activity.Class

navigationView.setItemIconTintList(null);
Share:
10,851
RoCkDevstack
Author by

RoCkDevstack

Not all knowing but doing my best to learn these, in-spite of my poor knowledge React Flutter WordPress Development SQL &amp; PHP NodeJS

Updated on July 26, 2022

Comments

  • RoCkDevstack
    RoCkDevstack almost 2 years

    Good day, Is there a way, displaying colored icons on navigation drawer? Not tinting them or setting them to black, and each of them will have corresponding color (highlight/background) when click, in navigation drawer.

    Just like Google Store App drawer.

  • RoCkDevstack
    RoCkDevstack over 8 years
    I tried that one. I added colored icons, but still it appears to be gray. Not the colored one. I'm using switch for intents. When the icons is click.
  • RoCkDevstack
    RoCkDevstack about 8 years
    Is this applicable also to vector images? Their original color? Thank you for your answer. :)
  • Android Geek
    Android Geek about 8 years
    @RoCk thanks for accepting the answer, you can also upvote if it is useful. well i didn't try vector images yet. I will explore and tell you then.
  • Android Geek
    Android Geek about 8 years
    @RoCk check for edit and please upvote if you find it useful :)
  • Alok Rajasukumaran
    Alok Rajasukumaran over 5 years
    what is the kotlin equvalent
  • fHate
    fHate about 3 years
    Edit save my life. Thank you.