Android OptionMenu Tutorial with Example

By | April 18, 2019
OptionMenu in Android Tutorial Example

What is OptionMenu ?

Option menu is a primary menu in android.it is primary collection of menu items for an activity. option menu used Like settings,search etc.Mostly android use to option menu is a toolbar top right of three dots.

option menu is a inflate by the inflate() Method called and in this method of MenuInflater class.

Option menu item need to perform event handling item to onOptionsItemSelected() you need to override in this method of activity class file.

Implementation of OptionMenu

Create activity_main.xml File

Create Menu Resource xml file to res/menu directory to create new xml file.For Example I have create menu example file and name given to option_menu.xml

Create MainActivity.java file

Now above the code is create option menu to create res/menu directory to option_menu.xml file create and insert three item in search,share and about items.now in this menu file inflate on onCreateOptionMenu(Menu menu) method. now when the user press this menu to called onOptionItemSelected(MenuItem item) Method called. in this method use to switch case statement to maintain case when user click menu item to display message.