MenuItem myMenuItem = menu.findItem(R.id.my_menu_item); myMenuItem.setIcon(R.drawable.my_menu_icon);
MenuItem myMenuItem = menu.findItem(R.id.my_menu_item); myMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // Do something return true; } });This code finds a specific menu item by its ID and sets a listener that is triggered when the item is clicked. Overall, the MenuItem class is an important part of Android development for creating user interfaces with menus.