Search code examples
androidandroid-optionsmenu

Change Icon from home Button in OptionsMenu


@Override
public boolean onOptionsItemSelected(MenuItem item) {


    switch (item.getItemId()) {
        case android.R.id.home:
            //action
            break;
    }

    return super.onOptionsItemSelected(item);
}

How can I change the Icon from the Back Button (android.R.id.home) in OptionsMenu?

Thank you!


Solution

  • switch (item.getItemId()) {
        case android.R.id.home:
            menu.getItem(0).setIcon(getResources().getDrawable(R.drawable.icon_converted));
            break;
    }
    

    Here menu.getItem(0) will the first menu, it should behave accordingly.