迁移到 Compose for TV
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如需从 Leanback 界面工具包迁移到 Compose for Android TV,请按以下步骤操作:
评估您当前的 Leanback 实现:确定您使用的组件(包括预构建 fragment 中提供的组件),了解界面的结构以及数据在应用中的流动方式。
将 TV 应用的各个屏幕迁移到 Compose,以便您逐步学习和适应 Compose。
使用 Jetpack 库利用 Compose for TV 中的专用组件。请参阅我们的设计指南,了解如何自定义和扩展现成的可组合项,以构建美观的 TV 界面。
调整数据和状态管理,以支持 Compose 声明式编程范式。适应可能需要您更改在应用中管理数据和状态的方式。请使用 ViewModel
和 Jetpack Compose 内部状态管理机制来管理应用中的数据和状态。
在迁移应用中更复杂的部分时,请测试并迭代。
如需解决遇到的任何 bug,请与活跃的 Android Stack Overflow 开发者社区互动,或通过我们的公开 bug 跟踪器提交 bug。
资源
无论您是刚开始接触 Compose,还是正在迁移到 Compose,我们都提供了丰富的资源来帮助您学习使用现代 Android 开发工具包 Jetpack Compose 构建 TV 界面的最佳实践:
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Migrate to Compose for TV\n\nTo migrate from the Leanback UI toolkit to Compose for Android TV, follow these steps:\n\n- **Assess your current Leanback implementation** by identifying the components\n you're using (including those that are provided inside the prefabricated\n fragments) and understanding how your UI is structured and how data flows\n through your app.\n\n- **Migrate individual screens** of your TV app to Compose so you can learn and adapt to Compose\n gradually.\n\n - While you can use both Leanback and Compose within the same app to allow for\n a gradual migration process, begin by replacing entire fragments at a time\n with a goal of converting your TV application into a single activity.\n\n - Start small. Don't try to migrate everything at once. Begin with smaller\n components like settings or account screens and gradually work your way\n through the app.\n\n - Refer to documentation and examples in the resources listed in the\n [Resources](#resources) section.\n\n- **Leverage dedicated components** from Compose for TV by using [the Jetpack\n libraries](/jetpack/androidx/releases/tv). Consult our [design guides](/design/ui/tv/guides/components) to explore\n how you can customize and extend ready-to-use composables to build\n beautiful TV UIs.\n\n- **Adapt your data and state management** to support the Compose [declarative\n programming paradigm](/develop/ui/compose/mental-model#paradigm). Adaptation might require changes in how you manage\n data and state in your app. Use [`ViewModel`](/reference/kotlin/androidx/lifecycle/ViewModel)\n and Jetpack Compose internal state management mechanisms to manage data and\n state in your app.\n\n- **[Test](/develop/ui/compose/testing) and iterate** as you migrate more complex parts of your app.\n\nEngage with the active Android [developer community on Stack\nOverflow](https://stackoverflow.com/questions/tagged/android-jetpack-compose-tv) for any bugs you encounter, or submit the bugs through\nour [public bug tracker](/jetpack/androidx/releases/tv#feedback).\n\nResources\n---------\n\nWhether you're new to Compose or are in the process of migrating to Compose\nalready, our large collection of resources are here to help you learn best\npractices for building TV UIs with the modern Android development toolkit,\nJetpack Compose:\n\n- [Compose for TV integration guides](/training/tv/playback/compose)\n- [TV design guides](/design/ui/tv/guides/components)\n- [Introduction to Compose for TV](/codelabs/compose-for-tv-introduction) codelab\n- [Library release notes](/jetpack/androidx/releases/tv)\n- [JetStream](https://github.com/android/tv-samples/tree/main/JetStreamCompose) video streaming sample app\n- [JetCaster](https://github.com/android/compose-samples/tree/main/Jetcaster/tv-app) audio streaming sample app\n- [Component samples](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:tv/samples/src/main/java/androidx/tv/samples/)"]]