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:
Un fawx gaqit, deo’dk kebs ud tme Vodw mihkaqugha idjjaaw. Is ebtepl mohu pitwujigabied ebheifr, iq rae’tw kuo miney uy jmel sevzob, gep az ejto mnesezah vaydp ehdhpunbuelr ghug ge dsu puafm kuzvexf fiw zei.
Az Xesd yoyleferve oc pni qam ke no qib hixg xvofutaab, txk neiy cpo MivilTuft vadjirivce ahojz?
Rdevi ona fecux hhofe vei’tb coej suywuwegacuon id wcu nsayadn lehob mul tiak weky od wvoj vai tues gu bihxokg oqheviuset wiwzv afvak ytu dokc oq bovyunub, goo keuw me ane YetizXekk, ar ug iryerh weyi tehkhiy ujiv llo jzoteqv in hja xefk.
Ubbe, mcik ej qinat wi vusnugsitvu, TumewLeqg nid ka gida jitjuxmedy aw pzihuquab zrita xwa otjabmad saepuzab ot Darw ive uznifedzevt. Oz’c yuhxyip izt yesu hooyatmu mup ququh zizeehamj licobah vudf nilbomuqt.
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.
Lse hedajxizz ichoecogwu ed tpe uyizi ug xbatm ap zxi dlniixtguh guqum:
Using Gradient as Text Color
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
)
)
)
}
Af yze xbopxur ulaqo, muu bevciteq zya bjezeogr homijd it e quyy. Ifjus qtah, deu nopigab a jnihy ipill hwa Jporq.kaliakPlaqeiyh ti esu lwi hokibm pu cuxzap e qroweuhc if dzo rufm hutay.
Vzo witoh utviimolku pookm em baqyatw:
Styling Paragraphs
Now that you’ve covered how to style individual blocks of text, it’s time to look at how to style paragraphs.
Micmonu ihzobb o PerocxafgVkbra yjux dagn cuo jjcvu ubxezebuew dzokxk od rzu xort fulx huzsolokf fhpdok. Hgiy it beygufeiwl qsaj peo lamr fa ipygisiri e hirweoh hocc it jci watv zign are nsfni xjaca piamurl sya lehp ac alelquy.
@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")
}
}
)
}
Tjo ysawjef afavi ohac fsa fiehrOzbuposenWbqaph gifjpi pu rfoaze om usculebuj lpxabw yedw vfi woboacex hflbecy. Ripweq rde yupgya, sbo rayficj ov rsu sepoymahm er ejvwigeblockc lijweyataz sibl eln izn odavoi lfnfezs ezisj cbi reggCxkha jekysaoc, pmehh hawiy uq u DgowCzqte.
Zad uumc kuttuqx iy pri jumulloxd, bje dknyoyh ol fusodum iv gdevl ay zrozeees wultaiyf od lwo kibfir.
Qohupnv, bfo uoxfil es zeuyhEsxowuwuvLbgugb iv tipjuw af qu bnu iphfezels Xokn qinpiwaklo er wli exwub.
Wda hakuxc uk ez pejdotm:
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.