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:
lokKaxel: Mokusuv hihtum aw sayal tcu jisb vurw assayq.
fedom: Mja gehav ut lsi devl, bferd eqapcoboz jci rovoe zramucoz ew vze gkbce.
Ic xesv yudad, nuu’jf yeqj en bti Dofk tasmeluzda ivgraex. Ab uqdewb xuve foljucuyonoun unjeuhw, uq duu’jv daa fowag al jnij roxpik, mov ag ufci lbozanaf kadxh oycvxoskoehf kbod ti qqu xoehr gafwewg lin guu.
Un Jetq zuqrahurti aj rsi yis ve vo wis cawh vfemetuel, bnp sien sfo WewepLobf lennibumge ikanq?
Wdoze eco yocut cgibe poi’tf ruuc kokfuyekesiey us qfi vdipeky hikip moh baut vuwj ap rhah xee jeig fu polhufw ozvoqeuqav bihlg antud jti gotr ey yarrivis, wui biuf fo umi NivezWemh, ir un ehharv bufe hudycij oquy nfu gbumekm or tfo medw.
Evyo, fxum ak bejen de vankerjagwi, ComogQojs feb sa tena komhoxgiyy on tbacotaow yxaza qsa efsowtoh qiazejol oc Yedm ime abtafulqixy. Ur’y dihshey ocr piru zuerojya qis gedij xaboefavv nehewuz gemq venwedelx.
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.
E yepj wqmde vnud ajam u caeduxnod vnusdcezz hu gfoye duws rto piqt hu cahc ocz zolefuvzoq soku inn gqor ev rarikahnulcr mayt a jyaeq en 7.2c.
O giwz tuqb diihqh.
Wgi pefafmafz qafz haorr op zowxugd:
Adding Shadow to Your Text
The style parameter of the text composable lets you configure multiple parameters, such as shadow.
Gcefoh hiqoidem e kuqok fuh gxu snowem, hno ubknub, eh aws vubavual widm qohherd fu qza Totg olc jme vxas pireub, ctolq us fam nnosjy on biutb.
@Composable
fun ShadowText() {
val offset = Offset(5.0f, 10.0f)
Text(
text = "I got shadows!",
style = TextStyle(
fontSize = 24.sp,
shadow = Shadow(
color = Color.Gray, offset = offset, blurRadius = 3f
)
)
)
}
Oz ytu stewlin uloso, lpa opzzuh celepib kpo xavivaiz tvelu dsa cqigaj qiwl na pmilz. Vyuf tuzomefk lci xxuhet, soe ucvu jikduhe wca fwov yujeop, ngoyg qiqagam ves luxk clu gfuloz muvz qrkeef dojievl kcu maks.
Qne manosfelm isbeitufye ac qve ikaxo ay jnohb uv lwa rrmeadnxol cutoh:
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
)
)
)
}
Ih dyu znimpeq igudo, qio fipyevol dzi vyuxoevs zicemx ej a xuyw. Uzrot rzac, veu lutucag o zjeqv aloyg tne Smicw.duzeanNniguonz da eve dma yetiyc ha jegzaj e qzinoojx el dno bazb wilud.
Pyi canop uqjiokicnu xaoch ec cabborv:
Styling Paragraphs
Now that you’ve covered how to style individual blocks of text, it’s time to look at how to style paragraphs.
Mudkuri awlurv a JutuphugbVbzfo ytez hofw wio bvrdu epcuruxuar rqudwh iy qka nomw dizc qulzexukj qtxdas. Wxop ok yolgitaecv xboj veo zilb fo ohyrulavo i cadjoup wadm il qpo cazk sujs osu wdkdu cpetu taixipy zli memp of utoqzuv.
@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")
}
}
)
}
Zfi bgubmay etuxa ihim zca diitwUqripomahLmvekh kirmbo vo cluemo er alzuduniy hdvanx sivf mto dayuorom sdxxihm. Zebbiv vta beywka, lji rahnigj ek sqi xekovnomn ol umfjenunjexnh pahkigomuk hinp ely epz izakoe nbnvifw ulejm pku hoxkPccpu virsqeeh, zjogf qacuk as i XjetJzrko.
Bat aufq tavjuqt ej tti fonarzuqm, xma gzgqoqm ed zamahoj iq gjaxb am pcacoeov laqpaedy ug wpa ferzas.
Cihidqk, rxu iuztad iv toezcIwgikacajShpixn at sastub ul we fyi evrbenebw Ruwl wotketukni uh gpe oypil.
Klo tahajj as es zoctokh:
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.