17

I need to disable a tint color for some icons in NavigationView because their color define category type. How can I do it?
Below picture shows my problem:
enter image description here

Denis Sologub
  • 7,277
  • 11
  • 56
  • 123

5 Answers5

20
navview.setItemIconTintList(null);

Good luck!

Derlin
  • 9,572
  • 2
  • 32
  • 53
Robert Banyai
  • 1,329
  • 12
  • 14
  • 2
    It disables color tint for all items – Denis Sologub Apr 02 '16 at 09:34
  • Sorry, my bad. Then you can use a selector like that : http://stackoverflow.com/questions/30967851/change-navigation-view-item-color-dynamicly-android – Robert Banyai Apr 02 '16 at 09:36
  • My problem that I need to use tint not for all items, only for specified which doesn't define some category. `ColorTintList` applies to all items in `NavigationView`. – Denis Sologub Apr 02 '16 at 09:39
  • 1
    Did you tried to get your menu item programatically, and modify the item's tint? – Robert Banyai Apr 02 '16 at 09:50
  • I try to set `ColorTintList` in `null` in `NavigationView` and use `DrawableCompat` to tint icons when I create menu but it doesn't work. All my icons became a black. – Denis Sologub Apr 02 '16 at 09:52
6

If you want change color of icon on seletion the below is the possible answer:

Change Navigation View Item Color Dynamicly Android

Otherwise you can set

navview.setItemIconTintList(null);

this will give the original colors of icons. and you can use colored and grey icons as per your requirements.

Community
  • 1
  • 1
Android Geek
  • 8,956
  • 2
  • 21
  • 35
3

In case this is still relevant for somebody, we found a solution for a similar issue recently.

Although it is not possible (at least on API levels < 26) to set a custom tint list on individual items, you can set the tint mode individually. This worked for us:

val itemsWithoutTint: List<Int> = listOf(12345)
for (i in 0 until getMenu().size()) {
    val item = getMenu().getItem(i)
    if (item.itemId in itemsWithoutTint) {
        MenuItemCompat.setIconTintMode(item, PorterDuff.Mode.DST)
    }
}

By setting the TintMode to DST (https://developer.android.com/reference/android/graphics/PorterDuff.Mode), the source (in this case the tint color) is ignored and the destination (the icon to be tinted) is left untouched.

2

For those who are using Kotlin, That's how it is done

val bottomNavigationView: BottomNavigationView = findViewById(R.id.bottomnavigationhome)

// * THIS ONE 
bottomNavigationView.itemIconTintList = null
钟智强
  • 459
  • 6
  • 17
-3
 Menu menuNav = navigationView.getMenu();
 MenuItem menuItem = menuNav.findItem(R.id.nav_subjects);

 // Disable a tint color
 menuItem.setChecked(false);

I hope it answers your question.

ntthnch
  • 1
  • 1
  • 2