I am trying set the icon of item menu inside NavigationView as TextDrawable. For textDrawable im using TextDrawable library, but once i set the icon for the menu item it only displays a black circle instead of generated drawable.
I did try my code to generate the TextDrawable outside the NavigationView and it displays want i need, but I can't manage to make it display as icon for my menu item.
To generate the TexDrawable:
private Drawable getLetterDrawable(String letter){
return TextDrawable.builder()
.beginConfig()
.width(20) // width in px
.height(20) // height in px
.endConfig()
.buildRect(letter, Color.RED);
}
To set the icon:
...
navigationView.inflateMenu(R.menu.menu_drawer_users);
Menu menu = navigationView.getMenu();
menu.add("Item text here").setIcon(getLetterDrawable("A"));
...
And this is the unexpected result:
EDIT:
When I set R.mipmap.ic_launcher
as icon i get the android icon but also in grey color, so i can only see its border. It seems that the drawable its being "tinted" when using menuItem.setIcon()
.
I did try to do the following, but without success:
MenuInflater mi = getMenuInflater();
mi.inflate(R.menu.menu_drawer, menu);
menu.add("Test");
menu.getItem(0).setIcon(R.mipmap.ic_launcher);
menu.getItem(0).getIcon().clearColorFilter();
menu.getItem(0).getIcon().invalidateSelf();
Question: How can I remove the filter and show my icon in colors?
EDIT 2 : After Andrea Basso
suggestion, I did manage to remove the tint from navigationView object, but i can't still see the letter inside the square. I only see the red square but no letter inside.
The main problem remains: how to put TextDrawable as icon on MenuItem
?