Created
November 18, 2015 06:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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