Example of creating menu for Android programming

This paper describes the creation method of menu in Android programming. Share with you for your reference, as follows:

Create a main.xml file in the menu folder under the res directory, as follows:

Note: two menu items are created here. The < item > tag is used to create a specific menu item, and then assign a unique identifier to the menu item through Android: ID and a name to the menu through Android: title.

Then open the activity and override the oncreateoptionsmenu() method, as follows:

Of course, it's not enough to just show the menu. The menu is not for viewing. The key is that the menu is really available. Therefore, the menu response event needs to be defined again.

Override the onoptionsitemselected() method in the activity as follows:

Run the program and press the menu key to display the menu items.

The menu will not be displayed by default. The menu will be displayed at the bottom only by pressing the menu key.

More readers interested in Android related content can view the special topics of this site: summary of Android layout skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solving methods, summary of Android basic component usage, summary of Android view skills and summary of Android control usage

I hope this article will help you in Android programming.

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
分享
二维码
< <上一篇
下一篇>>