Android中Menu控件的add方法

来源:互联网 发布:峨眉山旅游 知乎 编辑:程序博客网 时间:2023/12/03 09:32
public abstract MenuItem add (int groupId, int itemId, int order, int titleRes) Added in API level 1Variation on add(int, int, int, CharSequence) that takes a string resource identifier instead of the string itself.ParametersgroupId  The group identifier that this item should be part of. This can also be used to define groups of items for batch state changes. Normally use NONE if an item should not be in a group. itemId  Unique item ID. Use NONE if you do not need a unique ID. order  The order for the item. Use NONE if you do not care about the order. See getOrder(). titleRes  Resource identifier of title string. ReturnsThe newly added menu item. 


 

 

第一个int类型的group ID参数,代表的是组概念,你可以将几个菜单项归为一组,以便更好的以组的方式管理你的菜单按钮。
第二个int类型的item ID参数,代表的是项目编号。这个参数非常重要,一个item ID对应一个menu中的选项。在后面使用菜单的时候,就靠这个item ID来判断你使用的是哪个选项。
第三个int类型的order ID参数,代表的是菜单项的显示顺序。默认是0,表示菜单的显示顺序就是按照add的显示顺序来显示。
第四个String类型的title参数,表示选项中显示的文字。

原创粉丝点击