`

【翻译】(37)菜单资源

 
阅读更多

【翻译】(37)菜单资源

 

see

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

 

原文见

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

 

-------------------------------

 

Menu Resource

 

菜单资源

 

-------------------------------

 

See also

 

另见

 

Menus 菜单

 

-------------------------------

 

A menu resource defines an application menu (Options Menu, Context Menu, or submenu) that can be inflated with MenuInflater.

 

一个菜单资源定义一个应用程序菜单(选项菜单,上下文菜单,或子菜单),它可以用MenuInflater解压。

 

For a guide to using menus, see the Menus developer guide.

 

想获取使用菜单的指引,请参见菜单开发者指引。

 

* file location:

 

* 文件位置:

 

res/menu/filename.xml

 

res/menu/<文件名>.xml

 

The filename will be used as the resource ID.

 

文件名将被用作资源ID。

 

* compiled resource datatype:

 

* 被编译的资源数据类型:

 

Resource pointer to a Menu (or subclass) resource.

 

指向一个Menu(或子菜单)资源的资源指针。

 

* resource reference:

 

* 资源引用

 

In Java: R.menu.filename

 

在Java中:R.menu.<文件名>

 

In XML: @[package:]menu.filename

 

在XML中:@[<包名>:]menu.<文件名>

 

* syntax:

 

* 语法:

 

-------------------------------

 

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

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <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"]

          android:actionLayout="@[package:]layout/layout_resource_name"

          android:actionViewClass="class name"

          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>

 

-------------------------------

 

* elements:

 

* 元素:

 

* <menu>

 

Required. This must be the root node. Contains <item> and/or <group> elements.

 

必需的。它必须是根节点。包含<item>和/或<group>元素。

 

* attributes:

 

* 属性:

 

* xmlns:android

 

XML namespace. Required. Defines the XML namespace, which must be "http://schemas.android.com/apk/res/android".

 

XML名字空间。必需的。定义XML名字空间,必须为"http://schemas.android.com/apk/res/android"。

 

* <item>

 

A menu item. May contain a <menu> element (for a Sub Menu). Must be a child of a <menu> or <group> element.

 

一个菜单项。可以包含一个<menu>元素(对于一个子菜单)。必须为<menu>或<group>元素的子元素。

 

* attributes:

 

* 属性:

 

* android:id

 

Resource ID. A unique resource ID. To create a new resource ID for this item, use the form: "@+id/name". The plus symbol indicates that this should be created as a new ID.

 

资源ID。一个唯一资源ID。为了为这个条目创建一个新的资源ID,请使用该形式:"@+id/<名称>"。加号符号指示它应该被创建为一个新的ID。

 

* android:title

 

String resource. The menu title as a string resource or raw string.

 

字符串资源。菜单标题作为一个字符串资源或原始字符串。

 

* android:titleCondensed

 

String resource. A condensed title as a string resource or a raw string. This title is used for situations in which the normal title is too long.

 

字符串资源。一个简明的标题作为一个字符串资源或一个原始字符串。这个标题被用在正常标题太长的情形下。

 

* android:icon

 

Drawable resource. An image to be used as the menu item icon.

 

可绘画对象资源。一个被用作菜单条目图标的图片。

 

* android:onClick

 

Method name. The method to call when this menu item is clicked. The method must be declared in the activity as public and accept a MenuItem as its only parameter, which indicates the item clicked. This method takes precedence over the standard callback to onOptionsItemSelected(). See the example at the bottom.

 

方法名。当这个菜单条目被点击时要调用的方法。方法必须被声明在活动中作为public方法,并且接受一个MenuItem作为它唯一的参数,它指示被点击的条目。这个方法带有高于对onOptionsItemSelected()的标准回调的优先级。见底下的示例。

 

-------------------------------

 

Warning: If you obfuscate your code using ProGuard (or a similar tool), be sure to exclude the method you specify in this attribute from renaming, because it can break the functionality.

 

警告:如果你使用ProGuard(或一个类似的工具)混淆你的代码,那么请确保排除你在这个属性指定的方法以避免重命名,因为它可能破坏这个功能。

 

-------------------------------

 

Introduced in API Level 11.

 

在API级别11中引入。

 

* android:showAsAction

 

Keyword. When and how this item should appear as an action item in the Action Bar. A menu item can appear as an action item only when the activity includes an ActionBar (introduced in API Level 11). Valid values:

 

关键词。这个条目应该何时以及如何在动作栏中显示作为一个动作条目。一个菜单条目可以显示作为一个动作条目,仅当活动包含一个ActionBar(在API级别11中引入)。可用的值:

 

-------------------------------

 

* Value Description

 

* 值 描述

 

* ifRoom Only place this item in the Action Bar if there is room for it.

 

* ifRoom 仅放置这个条目在动作栏中,如果有空间给它。

 

* withText Also include the title text (defined by android: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 |.

 

* withText 还包含标题文本(被android:title定义)在动作条目中。你可以包含这个值和其它标志之一一起作为一个标志集,通过用一个竖线'|'分隔它们。

 

* never Never place this item in the Action Bar.

 

* never 从不放置这个条目在动作栏中。

 

* always Always place this item in the Action 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 action bar.

 

* always 总是放置这个条目在动作栏中。避免使用它,除非它是关键的,该条目总是显示在动作栏中。设置多个条目总是显示作为动作条目可能导致它们和动作栏中的其它用户界面重叠。

 

* collapseActionView The action view associated with this action item (as declared by android:actionViewLayout) is collapsible.

 

* collapseActionView 关联这个动作条目的动作视图(当它被android:actionViewLayout声明)是可折叠的。

 

Introduced in API Level 14.

 

在API级别14中引入。

 

-------------------------------

 

See the Action Bar developer guide for more information.

 

参见动作栏开发者指引以获取更多信息。

 

Introduced in API Level 11.

 

在API级别11中引入。

 

* android:actionViewLayout

 

Layout resource. A layout to use as the action view.

 

布局资源。一个布局以使用作为动作视图。

 

See the Action Bar developer guide for more information.

 

参见动作栏开发者指引以获取更多信息。

 

Introduced in API Level 11.

 

在API级别11中引入。

 

* android:actionViewClass

 

Class name. A fully-qualified class name for the View to use as the action view. For example, "android.widget.SearchView" to use SearchView as an action view.

 

类名。一个用作动作视图的View的完全修饰类名。例如,"android.widget.SearchView"以使用SearchView作为一个动作视图。

 

See the Action Bar developer guide for more information.

 

参见动作栏开发者指引以获取更多信息。

 

-------------------------------

 

Warning: If you obfuscate your code using ProGuard (or a similar tool), be sure to exclude the class you specify in this attribute from renaming, because it can break the functionality.

 

警告:如果你使用ProGuard(或一个类似的工具)混淆你的代码,请确保排除你在这个属性中指定的类以防止重命名,因为它可能破坏这个功能。

 

-------------------------------

 

Introduced in API Level 11.

 

在API级别11中引入。

 

* android:actionProviderClass

 

Class name. A fully-qualified class name for the ActionProvider to use in place of the action item. For example, "android.widget.ShareActionProvider" to use ShareActionProvider.

 

类名。一个使用在动作条目上的ActionProvider的完全修饰类名。例如。"android.widget.ShareActionProvider"以使用ShareActionProvider。

 

See the Action Bar developer guide for more information.

 

参见动作栏开发者指引以获取更多信息。

 

-------------------------------

 

Warning: If you obfuscate your code using ProGuard (or a similar tool), be sure to exclude the class you specify in this attribute from renaming, because it can break the functionality.

 

警告:如果你使用ProGuard(或一个类似的工具)混淆你的代码,请确保排除你在这个属性中指定的类以防止重命名,因为它可能破坏这个功能。

 

-------------------------------

 

Introduced in API Level 14.

 

在API级别14中引入。

 

* android:alphabeticShortcut

 

Char. A character for the alphabetic shortcut key.

 

字符型。一个用于字母快捷键的字符。

 

* android:numericShortcut

 

Integer. A number for the numeric shortcut key.

 

字符型。一个用于数字快捷键的字符。

 

* android:checkable

 

Boolean. "true" if the item is checkable.

 

布尔型。"true"如果条目是可勾选的。

 

* android:checked

 

Boolean. "true" if the item is checked by default.

 

布尔型。"true"如果条目默认是被勾选的。

 

* android:visible

 

Boolean. "true" if the item is visible by default.

 

布尔型。"true"如果条目默认是可见的。

 

* android:enabled

 

Boolean. "true" if the item is enabled by default.

 

布尔型。"true"如果条目默认是使能的。

 

* android:menuCategory

 

Keyword. Value corresponding to Menu CATEGORY_* constants, which define the item's priority. Valid values:

 

关键词。值对应于Menu的CATEGORY_*常量,它定义条目的优先级。可用的值:

 

-------------------------------

 

* Value Description

 

* 值 描述

 

* container For items that are part of a container.

 

* container 对于是容器一部分的条目。

 

* system For items that are provided by the system.

 

* system 对于由系统提供的条目。

 

* secondary For items that are user-supplied secondary (infrequently used) options.

 

* secondary 对于是用户提供的第二(不频繁使用的)选择的条目。

 

* alternative For items that are alternative actions on the data that is currently displayed.

 

* alternative 对于是当前显示数据的可选动作的条目。

 

-------------------------------

 

* android:orderInCategory

 

Integer. The order of "importance" of the item, within a group.

 

整型。条目在组中的“重要度”次序。

 

* <group>

 

A menu group (to create a collection of items that share traits, such as whether they are visible, enabled, or checkable). Contains one or more <item> elements. Must be a child of a <menu> element.

 

菜单组(以创建一个共享特征的条目集合,诸如它们是否可见,使能,或可勾选)。包含一个或更多<item>元素。必须是一个<menu>元素中的子元素。

 

* attributes:

 

* 属性:

 

* android:id

 

Resource ID. A unique resource ID. To create a new resource ID for this item, use the form: "@+id/name". The plus symbol indicates that this should be created as a new ID.

 

资源ID。一个唯一的资源ID。为了为这个条目创建一个新的资源ID,请使用此格式:"@+id/<名称>"。加号符号指示它应该被创建为一个新的ID。

 

* android:checkableBehavior

 

Keyword. The type of checkable behavior for the group. Valid values:

 

关键词。组的可勾选行为的类型。可用的值:

 

-------------------------------

 

* Value Description

 

* 值 描述

 

* none Not checkable

 

* none 不可勾选

 

* all All items can be checked (use checkboxes)

 

* all 所有条目可以被勾选(使用复选框)

 

* single Only one item can be checked (use radio buttons)

 

* single 只有一个条目可以被勾选(使用单选按钮)

 

-------------------------------

 

* android:visible

 

Boolean. "true" if the group is visible.

 

布尔型。"true"如果组是可见的。

 

* android:enabled

 

Boolean. "true" if the group is enabled.

 

布尔型。"true"如果组是使能的。

 

* android:menuCategory

 

Keyword. Value corresponding to Menu CATEGORY_* constants, which define the group's priority. Valid values:

 

关键词。值对应于Menu的CATEGORY_*常量,它定义组的优先级。可用值:

 

-------------------------------

 

* Value Description

 

* 值 描述

 

* container For groups that are part of a container.

 

* container 对于是容器一部分的组。

 

* system For groups that are provided by the system.

 

* system 对于由系统提供的组。

 

* secondary For groups that are user-supplied secondary (infrequently used) options.

 

* secondary 对于是用户提供的第二(不频繁使用的)选择的组。

 

* alternative For groups that are alternative actions on the data that is currently displayed.

 

* alternative 对于是当前显示数据的可选动作的组。

 

-------------------------------

 

* android:orderInCategory

 

Integer. The default order of the items within the category.

 

整型。条目在分类中的默认次序。

 

* example:

 

* 示例:

 

XML file saved at res/menu/example_menu.xml:

 

保存为res/menu/example_menu.xml的XML文件:

 

-------------------------------

 

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/item1"

          android:title="@string/item1"

          android:icon="@drawable/group_item1_icon"

          android:showAsAction="ifRoom|withText"/>

    <group android:id="@+id/group">

        <item android:id="@+id/group_item1"

              android:onClick="onGroupItemClick"

              android:title="@string/group_item1"

              android:icon="@drawable/group_item1_icon" />

        <item android:id="@+id/group_item2"

              android:onClick="onGroupItemClick"

              android:title="@string/group_item2"

              android:icon="@drawable/group_item2_icon" />

    </group>

    <item android:id="@+id/submenu"

          android:title="@string/submenu_title"

          android:showAsAction="ifRoom|withText" >

        <menu>

            <item android:id="@+id/submenu_item1"

                  android:title="@string/submenu_item1" />

        </menu>

    </item>

</menu>

 

-------------------------------

 

The following application code inflates the menu from the onCreateOptionsMenu(Menu) callback and also declares the on-click callback for two of the items:

 

以下应用程序代码从onCreateOptionsMenu(Menu)回调中解压菜单,同时还声明用于两个条目的点击回调。

 

-------------------------------

 

public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();

    inflater.inflate(R.menu.example_menu, menu);

    return true;

}

 

public void onGroupItemClick(MenuItem item) {

    // One of the group items (using the onClick attribute) was clicked

    // The item parameter passed here indicates which item it is

    // All other menu item clicks are handled by onOptionsItemSelected()

    // 分组条目之一(使用onClick属性)被点击

    // 传入这里的item参数指示它是哪个条目

    // 其它所有菜单条目的点击被onOptionsItemSelected()处理。

}

 

-------------------------------

 

-------------------------------

 

Note: The android:showAsAction attribute is available only on Android 3.0 (API Level 11) and greater.

 

注意:android:showAsAction属性仅在Android 3.0(API级别11)和更高的版本上可用。

 

-------------------------------

 

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

 

除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。

 

Android 4.0 r1 - 13 Jan 2012 0:46

 

-------------------------------

 

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

 

(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)

 

(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:

* ソフトウェア技術ドキュメントを勝手に翻訳

http://www.techdoctranslator.com/android

* Ley's Blog

http://leybreeze.com/blog/

* 农民伯伯

http://www.cnblogs.com/over140/

* Android中文翻译组

http://androidbox.sinaapp.com/

 

分享到:
评论

相关推荐

    unity 界面菜单翻译

    "unity 界面菜单翻译"正是为了解决这个问题,提供了中文翻译,帮助用户更好地理解和操作Unity。 Unity的界面主要包括以下几个核心部分: 1. **主菜单(Main Menu)**:这是Unity启动后首先看到的菜单,包含了...

    winrar 中文翻译资源文件

    《WinRAR中文翻译资源文件详解》 WinRAR是一款广受欢迎的文件压缩与解压缩软件,其强大而便捷的功能使得它在全球范围内拥有大量的用户。在使用过程中,为了方便中国用户,WinRAR提供了中文语言支持,而这背后的实现...

    一个ComfyUI的多语言翻译插件,这个插件实现了居民菜单

    在这个插件的帮助下,开发者可以轻松地实现各种组件的翻译,例如居民菜单、搜索栏以及右键单击上下文菜单等关键交互元素。 首先,我们来深入理解一下JavaScript在多语言支持中的作用。JavaScript作为前端开发的主要...

    pyqt、qt右键菜单英文翻译中文的qm文件

    pyqt、qt右键菜单英文翻译中文的qm文件,下载即可直接使用,对于QTextEdit、QPlainTextEdit、QLineEdit都可以正常显示中文 注意使用时压缩包中的两个文件qt_zh_CN.qm、widgets_zh_CN.qm都需要引入

    VC 多语言菜单实现

    - 用户选择语言后,调用`LoadLanguageResources`函数,然后重新加载菜单资源,使菜单更新为用户所选语言。 5. **使用BCompare工具**: - BCompare是一款强大的文件比较工具,它可以帮助开发者比较不同语言的资源...

    vc 关于菜单栏的设计

    1. **菜单资源编辑器**:VC++集成开发环境(IDE)提供了内置的菜单资源编辑器,用于创建和编辑菜单项。在这里,你可以添加、删除、重命名和排列菜单项,还可以为每个菜单项设置快捷键和图标。 2. **菜单资源**:在...

    VC简单编程实现多语言菜单

    - **翻译菜单项**:将粘贴的中文菜单项逐一翻译成英文,并替换原菜单项内容。例如,将 “文件/打开” 菜单项翻译为 "Open(&O)tCtrl+O"。 ##### 3. 加载多语言菜单 - **定义菜单变量**:在项目的主要窗口类(如`...

    Unity菜单翻译

    ### Unity菜单翻译详解 #### 一、概述 在Unity3D开发过程中,熟悉软件界面及其功能对于提升开发效率至关重要。由于Unity默认语言为英语,对于非英语母语的开发者来说,掌握常用菜单项的中文含义有助于更好地理解并...

    美食译苑——中文菜单英文译法(官方).pdf

    本资源摘要信息整理自《美食译苑——中文菜单英文译法》(官方全套完整版),该资源旨在规范中文菜单的英文翻译,涵盖中西餐饮食名称共3102个,包括2158个中餐。该资源共分三章,分别对中餐、西餐、饮品进行了标准的...

    中英双语菜单示例

    【标题】"中英双语菜单示例"所涉及的知识点主要集中...总的来说,"中英双语菜单示例"是一个涵盖了软件本地化、多语言支持、用户界面设计以及资源管理等多个IT领域的综合示例,对于理解和实践这些技术有很好的参考价值。

    单文档多语言菜单切换

    我们可以使用`LoadMenu`函数加载含有不同语言的菜单资源,并通过`SetMenu`函数将菜单设置到窗口上。在用户选择语言切换时,只需动态加载对应的菜单资源并更新即可。 3. **语言切换机制**:实现语言切换的关键在于...

    易语言双语菜单全操作.rar

    2. **菜单资源管理**:在双语环境下,菜单的每一项都需要有对应的英文和中文文本。这通常需要开发者使用到易语言的资源管理功能,将菜单文本作为资源存储,并根据用户的语言选择加载相应文本。 3. **语言切换机制**...

    realflow5 菜单命令翻译及基础教程.pdf

    《realflow5菜单命令翻译与基础教程解析》 在CG动画和特效制作领域,realflow作为一款专业的流体动力学模拟软件,凭借其强大的物理引擎和直观的操作界面,深受广大艺术家的喜爱。realflow5,作为该系列的一个重要...

    java树形菜单

    9. **国际化支持**: 如果你的应用需要支持多语言,记得确保树形菜单的文本可以通过资源包加载,以便进行翻译。 10. **布局管理**: 在WinFrom应用中,`JTree`需要被放置在合适的位置,这涉及到对容器(如`JFrame`或`...

    免费下载-ansys菜单翻译.docx

    总的来说,这份文档翻译涵盖了ANSYS软件的大部分基础操作,对于初学者和有经验的用户来说都是宝贵的资源,能够帮助他们更高效地进行工程模拟和分析。通过理解这些菜单选项,用户可以更加熟练地操作ANSYS,进行从几何...

    protel99汉化菜单

    "protel99汉化菜单"指的是将原本英文界面的Protel99软件菜单翻译成中文,方便中文用户使用。在这款软件的汉化过程中,通常会保留原有的快捷键设置,以便用户能快速适应和操作。 Protel99的汉化工作主要涉及以下几个...

    Unity3D菜单汉化翻译.pdf

    在Unity中,用户界面主要由一系列菜单栏组成,这些菜单提供了各种功能,帮助开发者实现游戏对象的创建、编辑、资源管理、场景构建等操作。下面将详细介绍标题中提到的八个菜单栏及其主要功能。 1. **File(文件)**...

Global site tag (gtag.js) - Google Analytics