The best, but not made, decision probably works on older platforms. In any case, in the new AppCompat21 +, the required method does not exist, and the getDeclaredMethod method returns a NoSuchMethodException .
So, the workaround for me (tested and working on 4.x, 5.x devices) is based on the direct change background parameter. So just put this code in your Activity class.
@Override public boolean onMenuOpened(int featureId, Menu menu) { // enable visible icons in action bar if (featureId == Window.FEATURE_ACTION_BAR && menu != null) { if (menu.getClass().getSimpleName().equals("MenuBuilder")) { try { Field field = menu.getClass(). getDeclaredField("mOptionalIconsVisible"); field.setAccessible(true); field.setBoolean(menu, true); } catch (IllegalAccessException | NoSuchFieldException e) { Logger.w(TAG, "onMenuOpened(" + featureId + ", " + menu + ")", e); } } } return super.onMenuOpened(featureId, menu); }
Menion Asamm Feb 15 '15 at 10:32 2015-02-15 10:32
source share