ย้ายข้อมูลธีม XML ไปยัง Compose
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เมื่อนำ Compose มาใช้ในแอปที่มีอยู่ คุณจะต้องย้ายข้อมูลธีมใน XML เพื่อใช้ MaterialTheme
สำหรับหน้าจอ Compose ซึ่งหมายความว่าการกำหนดธีมของแอปจะมีแหล่งที่มาของความจริง 2 แหล่ง ได้แก่ ธีมที่อิงตาม View และธีม Compose คุณต้องทำการเปลี่ยนแปลงการจัดรูปแบบในหลายที่ เมื่อย้ายข้อมูลแอปไปยัง Compose อย่างสมบูรณ์แล้ว คุณจะนำการกำหนดธีม XML ออกได้
หากต้องการย้ายข้อมูลธีม XML ไปยัง Compose ให้ใช้ Material Theme Builder เพื่อย้ายข้อมูลจากธีม XML ไปยัง Material 3 ใน Compose คุณสามารถใช้บทบาทสีที่มีอยู่ เช่น สีหลักและสีรองจากธีม XML และส่งไปยัง Material Theme Builder ได้ ซึ่งจะสร้างธีม Material 3 อย่างเต็มรูปแบบใน Compose และมีไฟล์สีและธีมที่ดาวน์โหลดได้เพื่อใช้ในแอป
Material Theme Builder จะสร้าง MaterialTheme
และรูปแบบสีสว่างและมืดสำหรับแอป หากแอปใช้รูปร่างหรือตัวอักษรที่กำหนดเอง ให้ย้ายข้อมูลรูปร่างและตัวอักษรที่กำหนดเองโดยกำหนด Shape
และ Typography
ตามลำดับ เมื่อกำหนดแล้ว ให้ระบุข้อมูลดังกล่าวแก่ MaterialTheme
ดูข้อมูลเพิ่มเติมได้ที่รูปร่างและการพิมพ์
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-27 UTC
[[["เข้าใจง่าย","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-27 UTC"],[],[],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."]]