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:
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.
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.
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.
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.
navview.setItemIconTintList(null);
Good luck!
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.
For those who are using Kotlin, That's how it is done
val bottomNavigationView: BottomNavigationView = findViewById(R.id.bottomnavigationhome)
// * THIS ONE
bottomNavigationView.itemIconTintList = null
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With