遷移至 Compose for TV
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如要從 Leanback UI 工具包遷移至 Compose for Android TV,請按照下列步驟操作:
評估目前的 Leanback 實作:找出您使用的元件 (包括預先建構的片段中提供的元件),並瞭解 UI 的結構和資料在應用程式中的流動方式。
將 TV 應用程式的個別畫面遷移至 Compose,以便逐步瞭解並適應 Compose。
使用 Jetpack 程式庫,善用 Compose for TV 的專屬元件。請參閱設計指南,瞭解如何自訂及擴充現成的可組合項,打造精美的電視 UI。
調整資料和狀態管理方式,以支援 Compose 宣告式程式設計典範。為了進行調整,您可能需要變更應用程式中資料和狀態的管理方式。請使用 ViewModel
和 Jetpack Compose 內部狀態管理機制,管理應用程式中的資料和狀態。
在遷移應用程式中較複雜的部分時,請測試並反覆進行。
如有任何錯誤,請與 Stack Overflow 上的活躍 Android 開發人員社群互動,或透過我們的公開錯誤追蹤器提交錯誤。
資源
無論您是 Compose 新手,還是已在遷移至 Compose 的過程中,我們都提供大量資源,協助您瞭解使用新式 Android 開發工具包 Jetpack Compose 建構 TV UI 的最佳做法:
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間: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/)"]]