Sometimes you don’t need huge menu. And int is’t super important create XML file for it.

You can just create your menu from code. It is very simple.

You need override

method. Let’s see the example below:

Here is you have created two menu items “Edit” and “Delete”. This menu items has showAsAction

. You can change it for your requirements. Also you can group menu items. For example my menu items in group with id = 0.

Also you can handle menu click actions. It is pretty same to XML menus. Let’s see:

As you can see it is very simple. You don’t need addition files in your project for just two menus. Use this approach.

Hope it help you.

Also here is link to github project.

Download it from github


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.