Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable a color tint in NavigationView only for specified icons

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

like image 583
Шах Avatar asked Apr 02 '16 09:04

Шах


People also ask

Can You disable buttons and tint their icons (sprites)?

In this tutorial: disabling buttons and tinting their icons (sprites) a darker color to indicate that they cannot be interacted with by the player. Here’s my game’s item vault. It displays a grid of buttons, each one representing an inventory “slot” and each button can be used to display an item the player actually owns.

How do I make the Settings button visible in navigationview?

This is a built-in menu item which by default is visible and placed at the bottom of the menu as shown a below. The NavigationView Class contains a property IsSettingsVisible which gets or sets a value that indicates whether the settings button is shown or not. Like all properties this can be set in the XAML or code.

What is the “Settings” menu item in a navigationview?

The last topic we need to cover in this post is the “Settings” menu item. This is a built-in menu item which by default is visible and placed at the bottom of the menu as shown a below. The NavigationView Class contains a property IsSettingsVisible which gets or sets a value that indicates whether the settings button is shown or not.

How do I change the background of a navigation menu?

Set the background of our menu items to a given resource. The resource should refer to a Drawable object or null to use the default background set on this navigation menu. Set the background of our menu items to the given resource. This overrides the default background set to items and it's styling.


4 Answers

navview.setItemIconTintList(null);

Good luck!

like image 184
Robert Banyai Avatar answered Oct 17 '22 01:10

Robert Banyai


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.

like image 38
Android Geek Avatar answered Oct 17 '22 00:10

Android Geek


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

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

// * THIS ONE 
bottomNavigationView.itemIconTintList = null
like image 40
John Melody Me Avatar answered Oct 17 '22 02:10

John Melody Me


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.

like image 1
Johannes Schamburger Avatar answered Oct 17 '22 00:10

Johannes Schamburger