1) Declare menu
in your class.
private Menu menu;
2) In onCreateOptionsMenu
do the following :
public boolean onCreateOptionsMenu(Menu menu) {
this.menu = menu;
getMenuInflater().inflate(R.menu.menu_orders_screen, menu);
return true;
}
3) In onOptionsItemSelected
, get the item and do the changes as required(icon, text, colour, background)
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_search) {
return true;
}
if (id == R.id.ventor_status) {
return true;
}
if (id == R.id.action_settings_online) {
menu.getItem(0).setIcon(getResources().getDrawable(R.drawable.history_converted));
menu.getItem(1).setTitle("Online");
return true;
}
if (id == R.id.action_settings_offline) {
menu.getItem(0).setIcon(getResources().getDrawable(R.drawable.cross));
menu.getItem(1).setTitle("Offline");
return true;
}
return super.onOptionsItemSelected(item);
}
Note:
If you have 3 menu items :
menu.getItem(0) = 1 item,
menu.getItem(1) = 2 iteam,
menu.getItem(2) = 3 item
Based on this make the changes accordingly as per your requirement.