將 XML 主題遷移至 Compose
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
在現有應用程式中導入 Compose 時,必須遷移 XML 中的主題,才能在 Compose 畫面中使用 MaterialTheme
。這表示應用程式的主題設計將有兩個可靠資料來源:以 View 為基礎的主題和 Compose 主題。如要進行樣式變更,您必須在多個位置進行。應用程式完全遷移至 Compose 後,即可移除 XML 主題。
如要將 XML 主題遷移至 Compose,請使用 Material 主題建構工具,將 XML 主題遷移至 Compose 中的 Material 3。您可以沿用現有的顏色角色,例如 XML 主題中的原色和次要顏色,並將這些顏色傳遞至 Material Theme Builder。這會在 Compose 中建立完整的 Material 3 主題,並提供可下載的顏色和主題檔案,供您在應用程式中使用。
Material Design 主題設定建構工具會為應用程式產生 MaterialTheme
,以及淺色和深色色彩配置。如果應用程式使用自訂形狀或字體排版,請分別定義 Shape
和 Typography
,遷移自訂形狀和字體排版。定義完成後,請將該資訊提供給 MaterialTheme
。詳情請參閱形狀和字體排版。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-21 (世界標準時間)。"],[],[],null,["When you introduce Compose in an existing app, you need to migrate your themes in XML to use `MaterialTheme` for Compose screens. This means your app's theming will have two sources of truth: the View-based theme and the Compose theme. Any changes to your styling need to be made in multiple places. Once your app is fully migrated to Compose, you can remove your XML theming.\n| **Note:** For non-Material design systems, see [Custom design systems in Compose](/develop/ui/compose/designsystems/custom).\n\nTo migrate your XML themes to Compose, use the [Material Theme Builder](https://m3.material.io/theme-builder) to migrate from an XML theme to [Material 3](/develop/ui/compose/designsystems/material3#material-theming) in Compose. You can use your existing color roles, such as primary and secondary colors from your XML theme, and pass them to the Material Theme Builder. This creates a fully Material 3 theme in Compose and provides downloadable color and theme files to use in your app.\n\nMaterial Theme Builder generates a `MaterialTheme` and light and dark color schemes for your app. If your app uses custom shapes or typography, migrate your custom shapes and typography by defining a `Shape` and `Typography`, respectively. Once defined, provide that information to your `MaterialTheme`. See [shapes](/develop/ui/compose/designsystems/material3#shapes) and [typography](/develop/ui/compose/designsystems/material3#typography) to learn more.\n| **Note:** If you are not using Material 3, see [Material Design 2 in Compose](/develop/ui/compose/designsystems/material) to learn how to create a theme. See [Migrate from Material 2 to Material 3 in Compose](/develop/ui/compose/designsystems/material2-material3) when you are ready to migrate to Material 3."]]