How to use menu to display icon and text at the same time in Android
This article mainly introduces the relevant knowledge of "how to use menu to display icons and text at the same time in Android", the editor shows you the operation process through actual cases, the operation method is simple and fast, and practical. I hope that this article "how to use menu to display icons and text at the same time in Android" can help you solve the problem.
Realization of displaying Icon and text at the same time by menu in Android
The menu entry in Activity, when setting its showAsAction= "never", displays only the text title by default, not the icon icon. You can override onMenuOpened () in Activity to make the icon visible by reflection.
/ / Let the menu display both the icon and the text @ Overridepublic boolean onMenuOpened (int featureId, Menu menu) {if (menu! = null) {if (menu.getClass (). GetSimpleName (). EqualsIgnoreCase ("MenuBuilder")) {try {Method method = menu.getClass (). GetDeclaredMethod ("setOptionalIconsVisible", Boolean.TYPE); method.setAccessible (true); method.invoke (menu, true) } catch (Exception e) {e.printStackTrace ();} return super.onMenuOpened (featureId, menu);}
Post my menu.xml below
So much for the introduction of "how to use menu to display icons and text at the same time in Android". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.