How to create Option Menu Example – On Hardware Click

Posted on .

Hello all , hope you doing great ! Today I am going to show you how to code on click of option Menu. This Option Menu is used for showing extra items or delete something and for searching.How lets dig inside –

Just you have to do is code in onOptionsItemSelected(Menu item) override method.
Download code

Lets start with designing your activity_main.xml file and paste the below code , This xml file is your common file you can do your normal stuff here like –

Now open your menu folder in your IDE and open main.xml file and paste the below code there-


Now open your file and paste the below code there and you have to work on onOptionItemSelected() method in which i have taken a Toast on switch case statements . You can code with your desires –

Now its time to Run your project in Android by pressing f11 .

Output –


option_menu example

Stay tuned for easy examples .For more queries comment on Disqus section :p