Method for creating option menu in Android

Using the optionmenu

Just override two methods

Public Boolean oncreateoptionsmenu (menu menu): initialization of menu public Boolean onoptionsiteselected (MenuItem item): menu response event

In addition, there are three methods that can be overridden

Public void onOptionsMenuClosed (Menu menu): public Boolean onPrepareOptionsMenu (Menu menu) is invoked when the menu is closed. The menu menu can be adjusted (dynamic loading menu list), public Menu, and call after the option menu is opened.

Loading mode of menu

Write menu XML file

First, create a menu folder in the res folder of the project directory, and then create the required menu. The code is as follows:

Next, we will load the defined menu XML layout file in the corresponding code and handle the response event:

Add method implementation

Add dynamically through the code. For the parameter menu of oncreateoptionsmenu, call the add method to add the menu, add (group number, ID, sorting number and title of the menu item). In addition, if the sorting number is sorted according to the addition order, fill in 0

The above is the creation method of option menu in Android introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>