顯示文字
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
顯示文字最基本的方法,就是以 String
做為引數的方式使用 Text
組件:
@Composable
fun SimpleText() {
Text("Hello World")
}
顯示資源中的文字
我們建議您使用字串資源,而非針對 Text
值進行硬式編碼,因為這樣您可以和 Android 檢視畫面共用相同的字串,以及做好應用程式國際化準備工作:
@Composable
fun StringResourceText() {
Text(stringResource(R.string.hello_world))
}
為您推薦
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-09-09 (世界標準時間)。
[null,null,["上次更新時間:2025-09-09 (世界標準時間)。"],[],[],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/30ed522851a9273c94afcd3a4c30bf674346ad18/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/30ed522851a9273c94afcd3a4c30bf674346ad18/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)"]]