Go to the menu.xml file, which contains the items.
Set the showAsAction attribute of the main item tag to always.
The icon attribute is used to set the icon in the sub-items tag.
The following are the main steps:
Using a menu xml file, inflate your PopupMenu.
If any of the items have an icon, repeat the process for all of them: if the item doesn't have
an icon, make one. This guarantees that items without icons are aligned with those that do.
In an XML file, create an Android Options Menu:
To design an options menu in Android, we must create a new folder menu within our project resource directory (res/menu/) and a new XML (menu example) file to build the menu. The example of defining a menu in an XML file (menu example. xml) is shown below.
Android's main menus are the Android Option Menus. They can be used for things like settings, searching, and deleting items. The Show Action property determines when and how this item appears as an action item in the app bar.
An Option Menu in Android is a collection of an application's major options from which users can choose one to execute a task. On the right side of the App Bar is the Option Menu.