Main Activity java |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.more, menu); return super.onCreateOptionsMenu(menu); }
//此重载旨在使能MENU中的ICON显示(4.0之后显示不了option menu icon) @Override public boolean onMenuOpened(int featureId, Menu menu) { if (menu != null) { if (menu.getClass().getSimpleName().equalsIgnoreCase("MenuBuilder")) { try { Method method = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE); if (method != null) { method.setAccessible(true); method.invoke(menu, true); } } catch (Exception e) { e.printStackTrace(); } } }
return super.onMenuOpened(featureId, menu); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.more_menu1: { ... } break; case R.id.more_menu2: break;
} return super.onOptionsItemSelected(item); }
|