Anyways, while doing the interface I noticed that it is really easy to create UI using xml especially menus. Android provides 3 kinds of menus: context menus, options menu and sub-menus. This post is about only Options Menu, I will cover the other 2 in later posts though.
Each activity has a single menu and it is created using the method onCreateOptionMenu, you can override this method and inflate the xml that contains the menu or you can add items manually, here is an example of both:
inflating the xml:
The menu structure is located in the noteslistmenu XML file. We are passing this file as a parameter.
adding them manually:
Basically both of them will generate the same menu but I prefer XML since it gives you the freedom to edit the file and add more items with out the need to re-compile the whole project again and it also allows you to add a lot more properties to your menu items.
This is how the menu looks like:
If you want to format the rows, you can group them or you can set the android:orderInCategory property. This property sets the order/priority of the items in the group and/or the menu.
This is another capture of this example and the XML file to generate it:
XMLmenu file
final result
Hope it helps some one. You can find more information about menus in the android documentation.
Happy coding :)
Happy coding :)
No comments:
Post a Comment