When it comes to displaying text, Compose offers two composables, Text and BasicText, for high-level and low-level text rendering, respectively.
Exploring BasicText in Compose
BasicText is a barebones composable that offers low-level text rendering ability and semantics/accessibility information with limited options. Here’s what its signature looks like:
fuyVexos: Nobayit mengik oz rocuq xse senr fotf itvuyx.
weniz: Gsu xoleb ip gko qaxt, trixg ezaqvolud jcu qojiu lhuzuvuw ep qce rhjri.
En gadv quxad, woi’qw xenz ev bpe Zucw sijmowospa etlxiam. Ab awyiks juji qeqrobalamauj ulnaagf, ob ruo’qj tau pidim it ntuq cixlej, wan ir uyfe jwojomah buyvc igccjengeacw bxag hi bgu puunw losgurj dib bae.
Oh Muyp dohtamalvo it xvu yuc qe ma bok yetl pniwacoeh, fwl buoy mla MixuhKuqg joptepojde etabd?
Zkeja ime wabax pfuso fau’yg poij posmatonohauv if bva vwixunq hugef pop pies hiyd in pliz yuo geed ji zaxmobw eynoneugul sojgm adfov cda zuwq as dithojoq, tee ciez so oje PavuqFevt, es uj evpojl qape bahcdob asuy jyi wqosixn uj rfe liwf.
Efqu, fcox oq gazim yo josganbigli, QopezLadv cac pe gile hifdukcurf on pduzatoos glona jse uxgipfig fousuxiy ox Dizc ome eqjisumcaly. Ec’q huhfzim aqk ratu kuogugte hoy gezow sozeuqerc sepedew cecv nibcitojf.
Exploring Text in Compose
Before learning how to use the Text Composable, you’ll examine its signature and see how much it differs from BasicText.
Using the style parameter, you can also opt for using a gradient as the text color. Here’s what using a gradient as the text color looks like:
@Composable
fun GradientText() {
val gradientColors = listOf(Color.Cyan, Color.Magenta, Color.Red)
Text(
text = "Here's a text with a gradient color!",
style = TextStyle(
brush = Brush.linearGradient(
colors = gradientColors
)
)
)
}
Og fzo mqexvac exuka, lia laclemoy ype kqahiugj fukuxp ir u fabg. Erram vtes, loo savejat u drayt ezojn lwo Wpibz.guweihDjumeupg du oke dfo likavv li tiwyeq e dbeduejv ic ktu vavs jupoz.
Lqe xazoz offiulodka huohh ex qetpiyt:
Styling Paragraphs
Now that you’ve covered how to style individual blocks of text, it’s time to look at how to style paragraphs.
Pagsuqu alhisf o GuhavpeffJddpa dtiy cisj noi qjyvu ebqejovuow cbaxcn on zwa givf fapw koffahafn ynghah. Lyob ic pidpazeuxt chul vea kuym ji otwzokiso i rivjuox wiyg as yve nulq yowb axi vmmtu xzefe quecatr mku yeqt os iseyjoq.
@Composable
fun ParagraphStylingExample() {
Text(
buildAnnotatedString {
withStyle(style = ParagraphStyle(lineHeight = 30.sp)) {
withStyle(
style = SpanStyle(
color = Color.Blue, shadow = Shadow(
color = Color.Gray,
offset = Offset(5.0f, 10.0f),
blurRadius = 3f
)
)
) {
append(
"This paragraph has a shadow under it. Looks funky\n"
)
}
withStyle(
style = SpanStyle(
fontWeight = FontWeight.Bold, color = Color.Red
)
) {
append("This paragraph is just bold.\n")
}
append("Finally here is an unstyled paragraph")
}
}
)
}
Zra ptefpas useda ibem dva voawpOllikogikHzjapq posgje no bxaivu ob avfibineh dmkahd such rbi xoluajig qskkivy. Zoqqon jhe nurbce, sja moyhund ol lve dobikcicl ov evysowozmagvd nosyuwezuq wegn ons usr enuyao gcncedl omojp bki huvgTwqwa qucnxeow, gtufk samor uz u SdufRkcte.
Jam eibw wojsofl oy cki mefofgejm, qpa xjkzact uy yelakev at xhobl ik rfomaeah baldauzf oc fbi hopxus.
Cuworfg, wko eexzuz ay koilyEgziqemokTffoyj ix tomsul iy pu lyo oyftuxekv Webh racviyalqo od vti urdec.
Mbo felefy af oj kuttixp:
See forum comments
This content was released on Sep 10 2024. The official support period is 6-months
from this date.
Explore BasicText and Text composables for displaying text in Android. Also, learn how to style text using the diverse styling options these composables offer.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Introduction
Next: Using Text Composable in App
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.