Android-res/menu资源文件(Menu Resource)
概念介绍
For all menu types, Android provides a standard XML format to define menu items. Instead of building a menu in your activity’s code, you should define a menu and all its items in an XML menu resource. You can then inflate the menu resource (load it as a Menu object) in your activity or fragment.
对于所有菜单类型,Android 提供了标准的 XML 格式来定义菜单项。您应在 XML 菜单资源中定义菜单及其所有项,而不是在 Activity 的代码中构建菜单。定义后,您可以在 Activity 或片段中扩充菜单资源(将其作为 Menu 对象加载)。
Using a menu resource is a good practice for a few reasons:
通过menu resource来创建menu,有以下好处:
It’s easier to visualize the menu structure in XML.
更易于使用 XML 可视化菜单结构
It separates the content for the menu from your application’s behavioral code.
将菜单内容与应用的行为代码分离
It allows you to create alternative menu configurations for different platform versions, screen sizes, and other configurations by leveraging the app resources framework.
允许您利用应用资源框架,为不同的平台版本、屏幕尺寸和其他配置创建备用菜单配置
表单使用介绍