资源类型概览
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本部分中的各个页面介绍了您可以在项目资源目录 (res/
) 中提供的特定类型应用资源的用法、格式和语法。
以下是对各个页面的简要说明:
- 动画资源
- 定义预先确定的动画。
补间动画保存在 res/anim/
中,可通过 R.anim
类访问。
帧动画保存在 res/drawable/
中,可通过 R.drawable
类访问。
- 颜色状态列表资源
- 定义根据
View
状态而变化的颜色资源。
保存在 res/color/
中,可通过 R.color
类访问。
- 可绘制资源
- 使用位图或 XML 定义各种图形。
保存在 res/drawable/
中,可通过 R.drawable
类访问。
- 布局资源
- 定义应用界面的布局。
保存在 res/layout/
中,可通过 R.layout
类访问。
- 菜单资源
- 定义应用菜单的内容。
保存在 res/menu/
中,可通过 R.menu
类访问。
- 字符串资源
- 定义字符串、字符串数组和复数形式,且包括字符串格式和样式设置。
保存在 res/values/
中,可通过 R.string
、R.array
和 R.plurals
类访问。
- 样式资源
- 定义界面元素的外观和格式。
保存在 res/values/
中,可通过 R.style
类访问。
- 字体资源
- 在 XML 中定义字体系列并包含自定义字体。
保存在 res/font/
中,可通过 R.font
类访问。
- 更多资源类型
- 将其他原始值定义为静态资源,具体包括:
- Bool
- 包含布尔值的 XML 资源。
- 颜色
- 包含十六进制颜色值的 XML 资源。
- 尺寸
- 包含尺寸值及度量单位的 XML 资源。
- ID
- 为应用资源和组件提供唯一标识符的 XML 资源。
- 整数
- 包含整数值的 XML 资源。
- 整数数组
- 提供整数数组的 XML 资源。
- 类型化数组
- 提供
TypedArray
(可用于可绘制对象数组)的 XML 资源。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Resource types overview\n\nEach page in this section describes the usage, format, and syntax for a certain type\nof [app resource](/guide/topics/resources/providing-resources)\nthat you can provide in your project resources directory (`res/`).\n\nHere's a brief summary of each page:\n\n[Animation resources](/guide/topics/resources/animation-resource)\n: Define pre-determined animations. \n\n Tween animations are saved in `res/anim/` and accessed from the `R.anim` class. \n\n Frame animations are saved in `res/drawable/` and accessed from the `R.drawable` class.\n\n[Color state list resource](/guide/topics/resources/color-list-resource)\n: Define a color resource that changes based on the `View` state. \n\n Saved in `res/color/` and accessed from the `R.color` class.\n\n[Drawable resources](/guide/topics/resources/drawable-resource)\n: Define various graphics with bitmaps or XML. \n\n Saved in `res/drawable/` and accessed from the `R.drawable` class.\n\n[Layout resource](/guide/topics/resources/layout-resource)\n: Define the layout for your application UI. \n\n Saved in `res/layout/` and accessed from the `R.layout` class.\n\n[Menu resource](/guide/topics/resources/menu-resource)\n: Define the contents of your application menus. \n\n Saved in `res/menu/` and accessed from the `R.menu` class.\n\n[String resources](/guide/topics/resources/string-resource)\n: Define strings, string arrays, and plurals and include string formatting and styling. \n\n Saved in `res/values/` and accessed from the `R.string`, `R.array`,\n and `R.plurals` classes.\n\n[Style resource](/guide/topics/resources/style-resource)\n: Define the look and format for UI elements. \n\n Saved in `res/values/` and accessed from the `R.style` class.\n\n[Font resources](/guide/topics/resources/font-resource)\n: Define font families and include custom fonts in XML. \n\n Saved in `res/font/` and accessed from the `R.font` class.\n\n[More resource types](/guide/topics/resources/more-resources)\n: Define other primitive values as static resources, including the following:\n\n [Bool](/guide/topics/resources/more-resources#Bool)\n : XML resource that carries a boolean value.\n\n [Color](/guide/topics/resources/more-resources#Color)\n : XML resource that carries a hexadecimal color value.\n\n [Dimension](/guide/topics/resources/more-resources#Dimension)\n : XML resource that carries a dimension value with a unit of measure.\n\n [ID](/guide/topics/resources/more-resources#Id)\n : XML resource that provides a unique identifier for application resources and\n components.\n\n [Integer](/guide/topics/resources/more-resources#Integer)\n : XML resource that carries an integer value.\n\n [Integer array](/guide/topics/resources/more-resources#IntegerArray)\n : XML resource that provides an array of integers.\n\n [Typed array](/guide/topics/resources/more-resources#TypedArray)\n : XML resource that provides a [TypedArray](/reference/android/content/res/TypedArray), which you can use\n for an array of drawables."]]