在 Compose 中绘制文本
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
了解如何使用专为在画布上绘制文本而设计的 Compose API。此部分显示了用于在圆角矩形中绘制表情符号字体的代码。
要点
- 在 Compose 中,您可以通过创建文本测量并调用
drawText
在画布上绘制文本,从而生成测量字符串。
- 您还可以自定义文本大小、对齐方式和其他属性。
包含本指南的集合
本指南属于以下精选快速入门集合,这些集合涵盖了更广泛的 Android 开发目标:
显示文本
文字对任何界面都属于核心内容。了解在应用中呈现文本的不同方式,以提供愉悦的用户体验。
显示图片
了解如何使用明亮动人的视觉元素为 Android 应用打造美观的外观和风格。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-02-06。
[null,null,["最后更新时间 (UTC):2025-02-06。"],[],[],null,["# Draw text in Compose\n\n\u003cbr /\u003e\n\nSee how to use Compose APIs specifically designed to draw text on a canvas. This\nsegment shows the code to draw an emoji font in a rounded rectangle. \n\nKey points\n----------\n\n- In Compose, you can draw text on a canvas by creating a text measure and calling [`drawText`](/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope#(androidx.compose.ui.graphics.drawscope.DrawScope).drawText(androidx.compose.ui.text.TextLayoutResult,androidx.compose.ui.graphics.Brush,androidx.compose.ui.geometry.Offset,kotlin.Float,androidx.compose.ui.graphics.Shadow,androidx.compose.ui.text.style.TextDecoration,androidx.compose.ui.graphics.drawscope.DrawStyle,androidx.compose.ui.graphics.BlendMode)), resulting in the measuring string.\n- You can also customize the text size, alignment, and other properties.\n\nCollections that contain this guide\n-----------------------------------\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\n### Display text\n\nText is a central piece of any UI. Find out different ways you can present text in your app to provide a delightful user experience. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/display-text) \n\n### Display images\n\nDiscover techniques for using bright, engaging visuals to give your Android app a beautiful look and feel. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/display-images) \n\nHave questions or feedback\n--------------------------\n\nGo to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts. \n[Go to FAQ](/quick-guides/faq) [Leave feedback](https://issuetracker.google.com/issues/new?component=1573691&template=1993320)"]]