Lalith's answer is correct.
You may also try this approach:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
invalidateOptionsMenu();
}
});
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem settingsItem = menu.findItem(R.id.action_settings);
// set your desired icon here based on a flag if you like
settingsItem.setIcon(ContextCompat.getDrawable(this, R.drawable.ic_launcher));
return super.onPrepareOptionsMenu(menu);
}