Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Tint in NavigationView to some icons

I want to keep some icons not tinted, and some tinted. Now I have:

app:itemIconTint="@color/menu_icons_selector"

It tints all icons.

I'm trying to make all icons not tinted

mNavigationView.setItemIconTintList(null);

and then

mNavigationView.getMenu().getItem(4).getIcon().setColorFilter(redColor, PorterDuff.Mode.SRC_ATOP);

to set tint only to 4th item, but this not working - all icons are now not tinted, and 4th also not tinted.

like image 448
diesersamat Avatar asked Sep 07 '15 11:09

diesersamat


2 Answers

This is working for me.... In this way you can tint individual Navigation MenuItem Icon Color Programmatically

navigation.getMenu().findItem(R.id.navItem1).getIcon().setColorFilter(Color.RED,PorterDuff.Mode.SRC_IN);
like image 164
Raveesh G S Avatar answered Oct 05 '22 23:10

Raveesh G S


You can "wrap" the icon as a drawable (res/drawable) and apply the applicable tint

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/ic_menu_icon"
    android:tint="@color/pink"/>
like image 41
Mitch Wong Ho Avatar answered Oct 06 '22 00:10

Mitch Wong Ho