androidandroid-studioiconsandroid-navigationview

Colored Icons In NavigationView


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.


Solution

  • 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.