Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 908
RoCk RoCk Avatar asked Feb 17 '16 10:02

RoCk RoCk


People also ask

Which attribute is used to set the color of the icon of the overflow menu?

The overflow background can be changed by defining a popupMenuStyle attribute in the theme. You should extend from Widget. Sherlock. PopupMenu in your own style where you can change the android:background attribute.

What is NavigationView in Android?

com.google.android.material.navigation.NavigationView. Represents a standard navigation menu for application. The menu contents can be populated by a menu resource file. NavigationView is typically placed inside a DrawerLayout .


2 Answers

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.

like image 192
Android Geek Avatar answered Oct 28 '22 16:10

Android Geek


You can set it in your Activity.Class

navigationView.setItemIconTintList(null);
like image 39
Francis Dominic Morales Avatar answered Oct 28 '22 17:10

Francis Dominic Morales