Android examples for User Interface:Menu
set Menu Icon Show Always
//package com.java2s; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import android.util.Log; import android.view.Menu; public class Main { public static void setMenuIconShowAlways(Menu menu) { if (menu == null) return; try {/*from w ww. j a va 2 s . co m*/ Method showIcons = menu.getClass().getDeclaredMethod( "setOptionalIconsVisible", Boolean.TYPE); showIcons.setAccessible(true); showIcons.invoke(menu, true); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { Log.e("tag", "InvocationTargetException"); e.printStackTrace(); } } }