Android : How to change menu icon

on Thursday, October 30, 2014


I have the following menu that i declare in Main activity :



public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);

//... populate with menu.add()

}


The menu icon looks like 3 dotts and it's position is on the action bar on the right side. In my app i use Fragments and i want to change the menu icon ( the icon i press to open de menu items ) depending on the fragment it's in front.


How can i do that programmatically?


Also on some of my fragments i don't want the menu to appear. For this i use inside those fragments :



public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
}


And i try to find a way using the menu var to change the icon of the menu. But i did not find a way.


So.... can you please show me how to change the menu icon programmatically?


Thanks,


0 comments:

Post a Comment