Jetpack Compose API 的样式准则
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如果您要为应用编写 Compose 代码或构建 Compose 库和 API,请遵循最佳实践,以使您的代码可扩缩、性能更高,并与生态系统的其余部分保持一致。
以下文档为使用 Compose 编写代码的任何人提供了指南:
- Jetpack Compose 的 API 准则:概述了使用 Jetpack Compose 编译器插件和运行时的任何系统的模式、最佳实践和规范性样式准则。其中包括以下主题:
- 基于 Kotlin 编码规范的 Compose Kotlin 样式指南
- 有关基于 Compose 运行时功能的
@Composable
函数和 API 的指南
- 使用和扩展 Compose 界面工具包的 API 的指南
- 设计 Compose API 时解决用例的模式
- Jetpack Compose 中
@Composable
组件的 API 准则:提供了一组用于创建和使用 @Composable
界面组件的准则和建议,包括以下主题:
- 创建和分层组件
- 为新组件命名
- 表达组件依赖项
@Composable
组件中的参数
- 遵循用于创建组件相关类和函数的正确模式
- 记录
@Composable
组件
- 改进组件的无障碍功能
- 更新组件 API,同时保持向后兼容性
受众群体
这些指南是为以下三类受众群体编写的:
- 基于 Jetpack Compose 构建应用的开发者。如果您在应用的某些部分使用 Jetpack Compose,则属于此群组。
- 致力于 Jetpack Compose 框架开发的开发者。如果您为
androidx.compose
库做出了贡献,则属于此群组。
- 基于 Jetpack Compose 创建库的开发者。如果您创建 Compose API 或 Compose 界面元素库,则属于此群组。这些 Compose 组件库可以是公开的,也可以是您公司或团队的本地库。
根据您所属的群组,每条样式指南的严格程度各不相同。例如,Jetpack Compose 框架开发通常会最严格地遵循这些准则。
如需详细了解每类开发者受众群体的要求,请参阅 RFC2119。
为框架和指南做出贡献
我们欢迎您为 androidx
代码库中的部分库和样式指南(Compose API 指南和 @Composable
组件指南)本身做出贡献。
如需贡献内容,请按照androidx
贡献指南中的说明操作。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):2025-08-27。"],[],[],null,["If you're writing Compose code for your app or building Compose libraries and\nAPIs, follow best practices to make your code scalable, more performant, and\nconsistent with the rest of the ecosystem.\n\nThe following documents provide guidelines for anyone writing code that uses\nCompose:\n\n- [API Guidelines for Jetpack Compose](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-api-guidelines.md): Outlines patterns, best practices, and prescriptive style guidelines for any system using the Jetpack Compose compiler plugin and runtime. It includes the following topics:\n - Kotlin style guidelines for Compose, based on the [Kotlin Coding\n Conventions](https://kotlinlang.org/docs/coding-conventions.html)\n - Guidance for `@Composable` functions and APIs that build on the Compose runtime capabilities\n - Guidelines for APIs that use and extend the Compose UI toolkit\n - Patterns for addressing use cases when designing a Compose API\n- [API Guidelines for `@Composable` components in Jetpack Compose](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-component-api-guidelines.md): Provides a set of guidelines and recommendations for creating and using `@Composable` UI components, including the following topics:\n - Creating and layering components\n - Naming a new component\n - Expressing component dependencies\n - Parameters in `@Composable` components\n - Following correct patterns for creating component-related classes and functions\n - Documenting `@Composable` components\n - Improving accessibility for components\n - Updating component APIs while retaining backwards compatibility\n\nAudience\n\nThese guidelines are written for the following three audiences:\n\n- **Developers building apps based on Jetpack Compose**. You are in this group if you use Jetpack Compose in some part of your app.\n- **Developers working on Jetpack Compose framework development** . You are in this group if you make contributions to the [`androidx.compose` libraries](/jetpack/androidx/releases/compose).\n- **Developers creating libraries based on Jetpack Compose**. You are in this group if you create Compose APIs or libraries of Compose UI elements. These libraries of Compose components may be publicly available or local to your company or team.\n\nDepending on the group you're in, you have different strictness levels for each\nstyle guideline. For example, Jetpack Compose framework development generally\nadheres most strictly to these guidelines.\n\nFor more information about the requirements for each developer audience, see\n[RFC2119](https://www.ietf.org/rfc/rfc2119.txt).\n\nContribute to framework and guidelines\n\nWe welcome contributions to select libraries in the `androidx` codebase and the\nstyle guidelines ([Compose API guidelines](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-api-guidelines.md) and\n[`@Composable` components guidelines](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-component-api-guidelines.md)) themselves.\n\nTo contribute, follow the instructions in the `androidx` [contribution\nguide](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/CONTRIBUTING.md)."]]