Di chuyển giao diện XML sang Compose
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Khi đưa Compose vào một ứng dụng hiện có, bạn cần di chuyển các giao diện trong XML để dùng MaterialTheme
cho các màn hình Compose. Điều này có nghĩa là giao diện của ứng dụng sẽ có 2 nguồn đáng tin cậy: giao diện dựa trên Khung hiển thị và giao diện Compose. Mọi thay đổi đối với kiểu sẽ cần được thực hiện ở nhiều nơi. Sau khi di chuyển hoàn toàn ứng dụng sang Compose, bạn có thể xoá tính năng tạo giao diện bằng XML.
Để di chuyển giao diện XML sang Compose, hãy dùng Trình tạo giao diện Material để di chuyển từ giao diện XML sang Material 3 trong Compose. Bạn có thể sử dụng các vai trò màu hiện có, chẳng hạn như màu chính và màu phụ trong giao diện XML, rồi truyền các vai trò đó đến Công cụ tạo giao diện Material. Thao tác này sẽ tạo một giao diện hoàn chỉnh theo Material 3 trong Compose và cung cấp các tệp màu và giao diện có thể tải xuống để sử dụng trong ứng dụng của bạn.
Material Theme Builder tạo ra một MaterialTheme
và bảng phối màu sáng và tối cho ứng dụng của bạn. Nếu ứng dụng của bạn dùng các hình dạng hoặc kiểu chữ tuỳ chỉnh, hãy di chuyển các hình dạng và kiểu chữ tuỳ chỉnh bằng cách xác định Shape
và Typography
tương ứng. Sau khi xác định, hãy cung cấp thông tin đó cho MaterialTheme
. Hãy xem hình dạng và kiểu chữ để tìm hiểu thêm.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-08-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 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."]]