Android Menu 文件(二)

引用自 http://developer.android.com/guide/topics/resources/menu-resource.html

<?xml version="1.0" encoding="utf-8"?>

<!-- menu 根节点,必须使用的 xmlns为命名空间,也就是约束文件 -->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- menu条目,必须是一个<menu>或者<group>的子元素 -->
    <!-- id为菜单条目的id -->
    <item android:id="@[+][package:]id/resource_name"
          <!-- 菜单的名称 -->
          android:title="string"
          <!-- 菜单名称过长时起作用,简要名称 -->
          android:titleCondensed="string"
          <!-- 菜单条目的图片资源 -->
          android:icon="@[package:]drawable/drawable_resource_name"
          <!-- 菜单条目点击时的方法,最好在代码中实现 -->
          android:onClick="method name"
          <!-- 菜单的展示方式,见下方表格 -->
          android:showAsAction=["ifRoom" | "never" | "withText" | "always" | "collapseActionView"]
          <!-- API Level 11中引入的 -->
          android:actionLayout="@[package:]layout/layout_resource_name"
          <!-- android.widget.SearchView -->
          android:actionViewClass="class name"
          <!-- API Level 14中引入,稍后请看示例 -->
          android:actionProviderClass="class name"
          <!-- 稍后示例 -->
          android:alphabeticShortcut="string"
          android:numericShortcut="string"
          android:checkable=["true" | "false"]
          android:visible=["true" | "false"]
          android:enabled=["true" | "false"]
          android:menuCategory=["container" | "system" | "secondary" | "alternative"]
          android:orderInCategory="integer" />
    <group android:id="@[+][package:]id/resource name"
           android:checkableBehavior=["none" | "all" | "single"]
           android:visible=["true" | "false"]
           android:enabled=["true" | "false"]
           android:menuCategory=["container" | "system" | "secondary" | "alternative"]
           android:orderInCategory="integer" >
        <item />
    </group>
    <item >
        <menu>
          <item />
        </menu>
    </item>
</menu>
Value Description
ifRoom Only place this item in the app bar if there is room for it. If there is not room for all the items marked "ifRoom", the items with the lowest orderInCategory values are displayed as actions, and the remaining items are displayed in the overflow menu.
withText Also include the title text (defined byandroid:title) with the action item. You can include this value along with one of the others as a flag set, by separating them with a pipe |.
never Never place this item in the app bar. Instead, list the item in the app bar’s overflow menu.
always Always place this item in the app bar. Avoid using this unless it’s critical that the item always appear in the action bar. Setting multiple items to always appear as action items can result in them overlapping with other UI in the app bar.
collapseActionView The action view associated with this action item (as declared byandroid:actionLayout orandroid:actionViewClass) is collapsible.
Introduced in API Level 14.
Value Description
container For items that are part of a container.
system For items that are provided by the system.
secondary For items that are user-supplied secondary (infrequently used) options.
alternative For items that are alternative actions on the data that is currently displayed.

下一篇做个示例