Java tutorial
//package com.java2s; //License from project: Open Source License import android.view.Menu; import android.view.MenuItem; public class Main { public static void setMenuItemEnabled(final Menu menu, final boolean enabled, final int viewId, final int enabledResId, final int disabledResId) { final MenuItem v = menu.findItem(viewId); if (v != null) { v.setIcon(enabled ? enabledResId : disabledResId); v.setEnabled(enabled); } } }