Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use menu to display icon and text at the same time in Android

Shulou Source: shulou.com Published: 2022-05-31 22:48:49 09月21日 Update

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.

Tags: Icons text at the same time knowledge industry different practical content practical practical articles methods more items cases knowledge points articles menus information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno macOS Microsoft Shulou Technology Huawei