Skip to content

Instantly share code, notes, and snippets.

@ydcool
Created November 18, 2015 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ydcool/026db2a169248769c9f3 to your computer and use it in GitHub Desktop.
Save ydcool/026db2a169248769c9f3 to your computer and use it in GitHub Desktop.
solve overflow menu icon not showing bug on android.support.v7.widget.Toolbar
/**
* solve overflow menu icon not showing bug on {@link android.support.v7.widget.Toolbar}
*
* @see <a href="http://stackoverflow.com/questions/30076392/how-does-this-strange-condition
* -happens-when-show-menu-item-icon-in-toolbar-over">StackOverflow question<a/>
*/
@Override
protected boolean onPrepareOptionsPanel(View view, Menu menu) {
if (menu != null) {
if (menu.getClass().getSimpleName().equals("MenuBuilder")) {
try {
Method m = menu.getClass().getDeclaredMethod(
"setOptionalIconsVisible", Boolean.TYPE);
m.setAccessible(true);
m.invoke(menu, true);
} catch (Exception e) {
Timber.e(getClass().getSimpleName(), "onMenuOpened...unable to set icons for overflow menu", e);
}
}
}
return super.onPrepareOptionsPanel(view, menu);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment