创建向后兼容的界面
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本课程介绍如何以向后兼容的方式使用新版 Android 中提供的界面组件和 API,以确保您的应用在旧版平台上也能运行。
本课程以 Android 3.0(API 级别 11)中引入的新操作栏标签页功能为指导示例,但您可以将这些技巧应用于其他界面组件和 API 功能。
课程
- 抽象化新 API
- 确定您的应用需要的功能和 API。了解如何定义特定于应用的中间 Java 接口,这些接口将界面组件的实现抽象到您的应用中。
- 使用新 API 代理
- 了解如何创建使用新 API 的接口实现。
- 创建使用旧 API 的实现
- 了解如何创建使用旧 API 的接口的自定义实现。
- 使用版本感知型组件
- 了解如何选择在运行时使用的实现,并开始在您的应用中使用该接口。
另请阅读
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-02-22。
[null,null,["最后更新时间 (UTC):2024-02-22。"],[],[],null,["# Create backward-compatible UIs\n\nThis class demonstrates how to use UI components and APIs available in newer versions of Android in a backward-compatible way, ensuring that your application still runs on previous versions of the platform.\n\nThroughout this class, the new [Action Bar Tabs](/guide/topics/ui/actionbar#Tabs) feature introduced in Android 3.0 (API level 11) serves as the guiding example, but you can apply these techniques to other UI components and API features.\n\nLessons\n-------\n\n**[Abstract the new APIs](/training/backward-compatible-ui/abstracting)**\n: Determine which features and APIs your application needs. Learn how to define application-specific, intermediary Java interfaces that abstract the implementation of the UI component to your application.\n\n**[Proxy to the new APIs](/training/backward-compatible-ui/new-implementation)**\n: Learn how to create an implementation of your interface that uses newer APIs.\n\n**[Create an implementation with older APIs](/training/backward-compatible-ui/older-implementation)**\n: Learn how to create a custom implementation of your interface that uses older APIs.\n\n**[Use the version-aware component](/training/backward-compatible-ui/using-component)**\n: Learn how to choose an implementation to use at runtime, and begin using the interface in your application.\n\n### You should also read\n\n- [How to have your (Cup)cake and eat it too](http://android-developers.blogspot.com/2010/07/how-to-have-your-cupcake-and-eat-it-too.html)"]]