Văn bản hiển thị
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.
Cách cơ bản nhất để hiển thị văn bản là sử dụng thành phần kết hợp Text
với
String
như một đối số:
@Composable
fun SimpleText() {
Text("Hello World")
}
Hiển thị văn bản trong tài nguyên
Bạn nên sử dụng tài nguyên chuỗi thay vì mã hoá cứng các giá trị Text
, vì bạn có thể chia sẻ cùng một chuỗi với các Khung hiển thị Android cũng như chuẩn bị đưa ứng dụng của bạn ra thị trường quốc tế:
@Composable
fun StringResourceText() {
Text(stringResource(R.string.hello_world))
}
Đề xuất cho bạn
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-31 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-31 UTC."],[],[],null,["The most basic way to display text is to use the `Text` composable with a\n`String` as an argument:\n\n\n```kotlin\n@Composable\nfun SimpleText() {\n Text(\"Hello World\")\n}https://github.com/android/snippets/blob/e4396f6dd13aaa8099c4baa671cdd549a10f201c/compose/snippets/src/main/java/com/example/compose/snippets/text/TextSnippets.kt#L107-L110\n```\n\n\u003cbr /\u003e\n\nDisplay text from resource\n\nWe recommend you use [string resources](/develop/ui/compose/resources#strings)\ninstead of hardcoding `Text` values, as you can share the same strings with your\nAndroid Views as well as preparing your app for internationalization:\n\n\n```kotlin\n@Composable\nfun StringResourceText() {\n Text(stringResource(R.string.hello_world))\n}https://github.com/android/snippets/blob/e4396f6dd13aaa8099c4baa671cdd549a10f201c/compose/snippets/src/main/java/com/example/compose/snippets/text/TextSnippets.kt#L116-L119\n```\n\n\u003cbr /\u003e\n\nRecommended for you\n\n- Note: link text is displayed when JavaScript is off\n- [Enable user interactions](/develop/ui/compose/text/user-interactions)\n- [Thinking in Compose](/develop/ui/compose/mental-model)\n- [Display emoji](/develop/ui/compose/text/emoji)"]]