Change background color of MenuItem on click

What's the correct way to change the background color of a MenuItem? I would like to change it to highlight that the MenuItem is active, but I haven't found how to do this.

I am currently changing the icon for another with a different color, but I don't need it, I just need to put some color on the background when clicked.

Here's what I do to change the icon:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.mnNow:
        item.setIcon(getResources().getDrawable(R.drawable.now_icon_active);
        this.displayFragment(getNowFragment());
        break;
    default:
        super.onOptionsItemSelected(item);
        break;
    }
    return false;
}

      

How can I change the background color when it is clicked and keep the color until the user selects a new option?

Thanks in advance.

+3


source to share





All Articles