How can I get an icon from the toolbar to be changed to a new one that I get with a method that is seen in a bbdd. The problem is that I can not access the event that updates the activity to be able to change the icon. I tried with the onPrepareOptionsMenu method, but I can not make it work. I have not been able to do this by putting the code in onStart because it tells me that the menu object is empty or invalid.
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
Drawable iconoMenu = obtenerIconoMenuCarro();
getMenuInflater().inflate(R.menu.menu_categorias, menu);
menu.getItem(0).setIcon(iconoMenu);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_categorias, menu);
Drawable iconoMenu = obtenerIconoMenuCarro();
menu.getItem(0).setIcon(iconoMenu);
return true;
}
My activities are extended by AppCompactActivity and loaded through an AdapterView. And I have the problem when I go back to the fragmentDialog or since the next activity.
Thanks.