I am developing an Android app. In my app I am using navigation drawer and navigation view. I am setting menu items for them programmatically. I set drawable image resource as icon to them programmatically. But when I set icon to them, icons are always black event my image resource beautiful color image.
This is how I programmatically set icon to menu
Menu menu = leftDrawer.getMenu();
SubMenu subMenu = menu.addSubMenu(MAIN_MENU_ITEM_GROUP_ID, 99, 99, "Others");
subMenu.add(MAIN_MENU_ITEM_GROUP_ID,96,96,"Monthly Leaderboard").setIcon(R.drawable.leaderboard_icon).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
startActivity(new Intent(MainActivity.this, LeaderboardActivity.class));
return false;
}
});
subMenu.add(MAIN_MENU_ITEM_GROUP_ID,96,96,"Settings").setIcon(R.drawable.settings_icon).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
return false;
}
});
This is the screenshot of what I have got
As you can see icons are black.
This is one of my original icon
Why is that happening and how can I fix it to get colorful icon? I have to set it programmatically.
Try the following line of code to resolve your problem...
yourNavigationView.setItemIconTintList(null)
And,
If you want to give specific color then You can change the color by using app:itemIconTint="@color/my_desired_colour" to NavigationView.
The default tint is black.`