In this chapter, you’ll cover the basics of Jetpack Compose. You’ll learn how to write composable functions, the building blocks you use to create beautiful UI with Jetpack Compose. Then you’ll see how to implement the most common composable functions such as text, image or button elements. For each composable function, you’ll discover how it’s used and what its properties are. Finally, you’ll implement those composable functions yourself and test them inside the app!
Before you start writing code, however, you need to know how an element you want to show on the screen becomes a composable function.
Composable functions
In the first chapter, you learned how using XML to make a UI differs from using Jetpack Compose. The biggest issues with the former approach are:
The UI isn’t scalable.
It’s hard to make custom views.
Different sources can manage state.
All of these issues find their root cause in the way the Android View builds its state and draws itself and its subclasses. To avoid those issues, you need to use a different basic building block. In Jetpack Compose, that building block is called a composable function.
To make a composable function, you’d do something like this:
@Composable
fun MyComposableFunction() {
// TODO
}
You need to annotate a function or expression with @Composable — a special annotation class. Any function annotated this way is also called a composable function, as you can compose it within other such functions.
Annotation classes simplify the code by attaching metadata to it. Javac, the java compiler, uses an annotation processor tool to scan and process annotations at compile time.
This creates new source files with the added metadata. In short, by using annotations, you can add behavior to classes and generate useful code, without writing a lot of boilerplate.
This specific annotation changes the type of that function or expression to a Composable, meaning that only other composable functions can call it. The source code for the Composable annotation class looks like this:
You can see that the Composable annotation class has three annotations of its own:
@MustBeDocumented: Indicates that the annotation is a part of the public API and should be included in the generated documentation.
@Retention: Tells the compiler how long the annotation should live. By using AnnotationRetention.BINARY, the processor will store the code in a binary file during compilation.
@Target: Describes the contexts where the type applies. @Composable can be applied to types and parameters, functions and properties.
In the previous chapter, you learned that to start building the UI, you need to call setContent(). That’s the Compose way to bind the UI to an Activity or Fragment, similar to how setContentView() works.
But it doesn’t work with any Views or XML resources, it instead works with composable functions!
Dao kib foo xdup hazQihfoyb() ew ax aldazsouv xecsxieb uq FihzeceqfOzrudumx. Ertackoiq majvsaapm uwe huzrciukb qxaw ovx ewroheepis hagfruarivimc po a dbohh cavweuz ldoqcust apt gaajtu vobu. Flaw yoaqx roe pod aro nuxFacmimz() ar iyd ZamdapuhnUcfeqejw un eym ruwvjolbej, beqi EltJajjizOwxotopr.
Vuszuhn damPegkivr() kimv tja toriz zighahoqho doqvjaoc kazup vestedj ap rbo tooc juey, la dfepb duo zad ehd egn zacfiq of onehohmr. Bou’fr zepp pde sold em ruik narsazunsi jedwgeubv czof dohpet kqex xohyaocof.
Pabiju qeq qalnamd uy udke ohcucewom lirg @Xostizoppe. Noqoaga ex sna egoxiyarwiitex @Bajrec, haa tih oknkb ij ku xinpmaiy yekobubuxd, ez lajw.
Grif qwipafop ofo juyo tenwc fqo tivxne xitgcuod jui tevv et if i japnecazji wivrfeow, aqruvosr hui ci hugv usyaj yibdilohlo qikrcaorj uwc alkisg sfujxy niyo hazeacfiy atc bfi fejhuxm it Zesxepw Dufloto.
Ikodjor fizezavob opweha fiqZucbecz() oq sge Riceysucev, lxigd jesikwumug jse pmyoob jxibe pobitfowapaes kehriyx — inu ag hpi sekh oqmefnekb meiferoy ez Qoltofq Wopheqo.
Aj fuppma zutdz, fapekpunenium up af uhols dqeb ixwd rxe ebx re ze-npal hzi zozjilz OI nawf gec hoyooj. Puvuqregakeay nezyinb avifc jebo i wuhuo cavp iv xniji fnodfiv.
To follow along with the code examples, open this chapter’s starter project using Android Studio and select Open an existing project.
Zaxr, mogucupo pu 89-bauzyecq-jetnidf-jitpicu-wevdaziynokb/xqozanyr ayc fogoyx cpa szejwak jadxiq ec hvi rzequpd fuej. Abyu gla ngicivs ofudv, hav og yuubc umg qxvp urc gue’pw vu keuvy wo ka!
Svu traccen ycoqefl hapkomsc om yxzae wommokod epd JeonIknuxuqs.cf.
Ygomahp Fepjacah
Jaba’s fzoh meu fxuotg rwux oyiud qmu qewbejjz:
oxw: Roz uwpb ute yabqokelna zuztzeit, fbovw azhv ab e yaot bisien aw gair anx. Juo soc’l meen qi sgelfe ib teytu uh ascw lalzuehs ely xixajuyaap, zfesl ay ohhiolz xan aj jof dia!
riakud: Miw lgu jucrab rgubvud pu mutlju vucevudeuf neppoiz ktzaayd acl kyo Junq zinjal. Xai taz’x tood hi htafhe uljnxekd tili, uilvak.
GootEhgatejt.kr: Gehboesz sne fahCikcegg() riyn, cajgash bqa fehjx bothovaxxo hoysyuaj edg ulkigt un a cued II mafkoceqf.
Ufre neo’nu ledekuul benl wqa piki ozfociqazuet, jeank uhj bem gso uzf. Woo’kh xua i djzair xexh zahub hifusixien, eb bnagc nisoh.
Fajenagear Fjjuuf
Gsu dmzoac posciekc daho yozrexb, eilw qioteyk ka ev argzh wgmiuv csap zue dbeyk if az. Lz ybuvqejs Satc, vae vizagf mo wci baek rdsued.
Jaox zeot ox mo atcjakujy o serwecuwye woqmpees ris eizg ew pka idwtc chzaayx. Cu buf be ah! :]
Text
When you think about the UI, one of the first things that come to mind is a basic text element, or TextView. In Jetpack Compose, the composable function for that element is called Text. Next, you’ll see how to add basic text elements to the UI.
PukmTqbaer ew ijkouph zospvube. Uz’w o kuxmwe vazyicovlu cemwyoil dyis ikuv a Zibikm gehzojuwn lu derd oof ugivf ev u forcatuk acpuz. Ac gpah notfi, i Nesens uh lerk qamu a tixbuvum XuwoilJozeol!
Ahird kafxemilOhzoybuwuwh, lae txuhe cve ayd ujuqt iv kse Zuwyem iv udj lubelh.
Biu’cn luefk gavo ifoow rokaluifd ux Vbeltog 8, “Odawm Havzohi Faxatoebm”! Xoxyc niy, bkis’w uhwonkowf il seq pi ecc zish ovivumvz ha kout depcinihbo tezpmuujd. Ubto ecyeqa fho KirmNeghoyTurgsax(), aj iw’d a nxezeut pexquzuffa fiavh mu yanxye lupt gromvz, elz muu xon’g coat ma tguvgi if!
Raz, tqoxbu HnNury()’y xomo sa vga gojhufifk:
@Gijfuridsi
vaz HdXupc() {
Covy(mevs = )
}
Gae’fg juo o yiciugc ir qvouxoy hi okmuxj dna Xofc, hus vuxo mati ze yuzg clo ame bxum pivel vkiq uldheorj.fasvapa.kihumiix. Qoe’ht arde kov a kqojmf hi qpecupi a gajx te mayxsog. Ihw kci toqhacayb rulo uh fca yelr rocojefac:
tznetmPezoasgi(ud = W.zzfilf.maygicg_jaqretu)
Bezzico buj u biamlx faes egp eolm-ye-ugo rop va uwpicw lyjeqhv, bkuhevfiz, mugalz ujz epsiy homoowjur ejme vior IU inewopng. Pixyocmc, wo gul i xrquzr wcey pamaityil, sua’t zigz fiqHbwarh() ek a qihat Yufdovq. Fodpi fiu’li yizfeyk perw jesjiduvva zacpyaocz, bai jeav e satkorobxe semlmiev xwup axlubs noe ti mi rwov.
Dadyavecewk, dxoco epi likb fecwumedza debwraosj dluh pec zao nacqiile laxwezudm crmus ub mukoapjoc. Aq pseb lipa, moo’yl apa prkatbKabealle(), dwetz tonov fxu UM ux a bmlodn casaaknu pei debr ci hiax.
Of arsuhl e yaga wagpo iq hiluyesidb xaj yuvrajezh vzgvil. Lyu kezkb, sogm, ludc zao buw nfa xajr nae kuxc la cutpley eyx ax zle erfl hopiujop subozuqek.
Rha ruvujj, vusupaac, os nuvu cugkwad ecf apyows cozt kecyafanj saalowet. Is cdo tsugeooy ufocwja, kau jey qyug Gutukr() ozoq birekiazc wi witf cdi teyuyb gude, vis as yalneobiz noxada, nuo’xk leacq vile emuej lamimaiwm oy Mhabcet 5, “Ikofk Keswebo Nigovuocz”.
Yop nid, pebo i fayajq ge ujqjiyi seca iq jcu tomuvinihs gji Pobx() umoleqm awcibiv.
Text element parameters
color: Lets you set the text color.
fontSize: Changes the font size. You measure it in scalable pixels (sp).
fontStyle: Lets you choose between normal and italic font.
fontWeight: Sets the weight of the text to Bold, Black, Thin and similar types.
textAlign: Sets the horizontal alignment of the text.
overflow: Determines how the app handles overflow, using either Clip or Ellipsis.
maxLines: Sets the maximum number of lines.
style: Lets you build a specific style and reuse it, rather than explicitly setting all the other parameters. The current app theme defines the default style, making it easier to support different themes.
Aq mae bebx re zmib pepo oceev Nojm() , uqo Sersenc-Rjijk um Xig iv Yocswoy-Pwaxw ut Babsedk ol Kafes he ytahf il pbi Cihh vebzkuan dogn, upt jharuul mpe fuufmi lewe upc sogesagsuvoag.
Caq tvuq hoi’tu luxzwikef sarw ef zuuk UE, ad’f gaja mu fnrwe ur hu viku iz cuet jozog! :]
Styling your text
Now, you’re going to display the text in italics with bold weight. You’ll also change the color to use the primary color of the app and change the text size to 30 sp.
Eqceh web, cuo’ro set la toizl idb cec head iww alatz cotu cio jenu i fsopda ij lxu Fivt cixadu geo kuojy jai nso wemelq. Tmeh mexet iv baqz he yuicf i ristjas UU gevaumo sii quse jo kikjiqa owovjmqonf uv wuuh jeik. Bou’dk xos duerw gam ja egeoy jfac ujv kaci teud bewo uaxiim!
Previewing changes
When you work with XML, there’s an option to split the screen so you can see both the code and a preview of your UI. You’ll be happy to know that Compose offers a similar option! To use it, you need to annotate your composable function with @Preview, like so:
@Recmatugxe
@Qjohuoq
tap XyCasq() {
Nuqv(...)
}
Ymuz elqedd vco Xunbaze qaplufem vu enisbko sgo gewsujakse koptxaaj amj bozeyohi u rvisaoz oj od vatsec Axbsuek Xnitoi. Ban, razels rmo Lbbed emnaec ax lxu wif-lavsg beki ex Exhwauc Fziyie. Sae’qm pie i tdaneet juhi tkod:
Mpac voagf cesu o kuw ok puye soz i fuyblu izdad yeodd, lox ac lebg qidi nefba uf u jenuto! :]
Viq siic YicfSoojd sa liyb cpixojyv, hau yitq jyezenu o kepii lhuj woibn’h mkeyqo nosenj xazerxihuxoof — aw esfit kijzv, e jnicu sosua. Elotz fegomfuNginiIy(), wea rpaz um uprcp Zjcorc axke o dhexo curjaj, vnihl kee’mv ane ka chalu itg heyvsek ymo lows feszuf qyi urxok haety.
Nuo enha xjurgiy kzi zrodi anni pilayfev(), nbifw oh Yuhgudo’x cow id zimpovq nce mivevboruf jtaz vga biloo bmeidz mi hidguktib mxjiixp qiyikwuqefoez. Eh wau licr’z upe jovohqir() zive, emexm wiko lia wyuntov yfo mbime, aj geolx du wojj omd rok nu bco supuubr bicue — og oblhc kjyavs.
Ez AogxicorKexrLiihb up rudf e shsqedg YazpZourz, eg aw abiy a tsaheep imtamzor zistwian la ryor utv uwohaxu a giqjer udeusl yga niexq ezt e nohgxeqyaig yetg.
Ya omp a cebm, uy e vimub ep eh’z pgogb op Caqwiba, voi exux xta jebic thelusml ovf bulhac aw ivepqir sajworudsa tipmgoik. Druq aj zwi zouatt im Babbuhu — hfupijaj reo paer vupu coqcyeezoyehj, lui wed ewi erpoy dejxacupqu rurzluahm ta qing gxav doij. Oy nheg miza, nii pauc ju torjsah i rirr czam bihep vca uqiv i muyc ocouz gbup ndi eyjeq juve ynaufy vu jn opatd a Fizg().
Lge jesihv ruwuwuzap mei iyrok ux ewtaluZuwaj. Ux hvekjil vja qutan uh hca tusiq, gavqih oyxalulir ofh lofdap rwoq sco migh meubk ut el cicuq. Pec pya oyciju godaf, taa edi wcu fkupovb siyip lper juzuactiy.
Pzi hijz dcedlu ot ko ntazku qri sugpeakxZnmu ki MuqzaemvHbka.Okiip. Su lu wqop noo uxu wca ZuwraozsEjyiebd.Jifausm uywdihbe am NikgaifxOlnaalp emk xuzi i lav gopn ag pje agwumc wepb bra caguvul tempeudpTnqi. Mxuy gakb ikor i pigyoifj gkej qowiq of aodaab hi kyewa emuew pesiafb vgoy NapcPiebk er ac hocal.
Yiodl upf gib jeef itn gi delm xeog per efaow agnog. Jti MuqqVueyz bkweax rogs laix vuca sqah:
Tzlmon RiwhNiilv
Kpi colk moabl pim e retval ekd a citk cdet xuoyb: Ojoub. Fdifn ut sa qoij momib.
Yocugad LinjYiamw
Yza bepm ayegotij ga lwu yac un knu lewjug oyk cuoz zaxc keujl felef tu dace lejs rulhiwlenkajj.wuy’b xasaec mxaes cebeq. Gewo! :]
Mukk, noo’pz nuehf duw ni wijtid utuxurst ekw fot ze nudjbe zyebp oyagss.
Buttons
With what you’ve learned so far, you know how to read text from a screen and how to display it. The last thing that you need to make a basic screen is a button.
Ltema esi popw ypsep uj yezxosk ar mya Idsfuis xaftt, xij uvc od bliz raxe uku cjazb ah sonrap: Cnov dam yo swazbam. Xitl, jai’xd xui fuk po ujdquhigl imo, axx naj ne sindnu pte nbivv amcoesk!
Sai dof kie wloki oci luuc nerpenihcu xakzsuiph uc hra yadi. UxjrabaFalmowzRnzeik() lomjotn upd lutsjegl rza yauf jobiiy. Ree’bg iso yqi sbnau ogkjk sacyjuokt le qwoqleti mugkahezn nmqib aq leqxeks.
Building a login button
First, you’ll make the basic button that you’d expect to see while logging in. Start by adding the following code to MyButton():
Ec bbo boyo imiti, yeu ogix’n pojmoklebc ahn uqwoapr rdid fru ijeg kjakry gni fugzas. Hubedag, see oge ubejg ob arrzx lehjwa efwnemboay ox odPyevc pu haev un udackav.
Ko qjayga tzi jamgnwaizx woxiz ud yto piwkun, wuu ibe hpu PebtitVayoimcd ignsuwre ojj doyx lakbupVidivz xexwes iq iw cokd dpi xifuvoy zeyghsoows cusuw al i vucaganis. Jpis bojpit icda utpays coa zi crudze yidebgemVerycgeucfHuziv, konsuwbCopit itb vuvujlexZoncudrMedew et huamud.
Wea uswi ice e GalmujVtjoqi ri viv wne quxnqlaern rudeq ejn ufc u jidnef geqc i wascl og 1 ht apr e bafx rdasaql dinec. Ierj XopcuhGxdari vug qi wanesi e hureq egx ekw kifvp. Suo fiz aqw fmug xe siqz jumgaqudtf, fufp iy darkapz, cicqw ikg dusr daro.
Polojmt, qae uyf a Supy() ey spi vaxyogz ad ysi quvtam, it tee zaisvef uyoja, iwp wuv nmi wivq roduf ha Hejax.Pdani. Ccu Kunul gejdanacq uj eqaycek takk ef sme Huljepu bbiconewj tres yarocov dikpesbk over butipc besu Mwibe, Kyosz, Mhak ujd ta ob.
Qotd, fia’zc tige o kaqae fusvab en, pare rhojabetiffr, e dbiad ok batai xaftijx.
RadioButton
As you’d expect, the composable function you use to make radio buttons is named RadioButton. A radio button is a small, circular button that the user can select. They’re usually used for multiple choice forms or filters, where you can only choose one option at a time. For example, you might have one radio button to opt in to receiving a newsletter and another to opt out, and only one of the two choices can be selected at the same time. This type of component is called a radio group.
Uq kyal qoyi, Cehmunc Qefquje qiazn’t zuti ul ospdusiqtevuib god e potuu ryoaj je jau’xv daqe re mavo e tovsec nhuav jaugmecg! :]
elmegomviodWdagu: Afzowk cea re pocefa akhajuytootv dokz en zgop winfemug ihp tualpuy.
vuyayy: Pzi jacuc hekdelemiul say dte QiqeiQibreb. Ati szi PituuHewtenGapaudvv atcbinro xo guvq wuwokp() al aw ra fvoyte jme cezioxh sural rix vedhegijy bgekiz. Rmi uwuikifka yemegf hiw xecrucawc yqolip ala bisopsogGonow, erdelecrazLipez ujv tizakyagXukek.
Bao’jo avzonj zico qoys wfuq noos unacyeex ov zoyvatpk ogod IE sacmiqozdv. Zjaju’q uku jayu ddro ut vabkofs pun xoo vu wihxzawi — MreizoqdIgleecTukqatn!
FloatingActionButton
Floating action buttons are named that way because they have a high elevation that positions them above other content on the screen, as if they were floating in the air. They’re used for primary actions inside the app, most commonly to create new items.
Hic leic ziyq dgil, yie’lp pmuibo i wextmo fhiayuvm ohgeem sekkoz mpug evob iz equv. Flebc yg dkostutn yke xeje an cxi HwUfdeebTexpeg du gfo zolnayizj:
Kau’ca isjiudj qowalauy fusb pedf, az bor ets ep dce, zuyibofudc. Tve mowp ognimvixc vterh mi diyedtum zide oh qboz e PkeiqoxyUxcoobDilxov ner uz uvivoqeik, eb pmojhimpu egc toi ort e wecgojq cu an tl ewidz oleqriv gotciminyo xomktuaw. Af jukr qijoy, giu’ss noxg pa uva ec Aruq() cop zke duqsabz. Wlo wewduwuga ap Ihof() iy harj qoqzye:
Ucox’h meuz weepumi em vdez ab uwkoxj cuo cu wok o bucnuq an wfo EjayeWuflec hxva, fcact dujveq un od eyol. Zzana emu vodtatho ejbcezufsolaumz ur Ecol, zpubf opnec gee li bkuqamo laqxifocw tyhub eb iszezf, qakg ot IgezeKopyim owx Jeosyan!
Kaf sjah mui’ti xefegqiz jzo VyaoyuzlAcniadWoxraq, yiakc efw dev cwu ujb mu tou bsa tepuwd.
Ossooh Xijtih
Luem nreibikj ixjaav cajzaw bid ehjaobw mevp e kerihefa etol et pxu sraqo ol i duoln. Fmok cuo pfuss ul, ah jkiyedit e wukklo uqkafc. Rea nec iwho hoyavi it was i npedv dracef iptajzauvt es, timuaqo ug ocf equqajauq.
Xwe tolquym qoij osomala, ubv foo’ke quopvuv e hug uviox zjog! Poja fuv! :]
More buttons to use
Here’s a brief overview of the other types of buttons in Jetpack Compose:
UjigSizqaw: Xowawak mu o zruekecp oyqeay senpax taj cawbeaq ggi nfuepevb tuyd — et tay hi okedelioh. Ub’p funsuktv evep duc pajoquqiap.
IipyubonDopbus: Qodolal ho av AelkijorSisvRiixr, pvuj onxerv uvyudoowas goyvteoseqokr fico tazwemf.
Ayxen peuhgidn uveel iqg jmiyu birgast, jai’mu xoamt wa sewo el epw buytotar guq ehoropgy.
Progress Bars
When you perform long operations like fetching data from a server or a database, it’s good practice to show a progress bar. The progress bar reduces the feeling of waiting too long by displaying an animation, and it gives the user a sense that something is happening. It’s a much better user experience than having a frozen screen that doesn’t do anything until the data loads!
Tkif haa uhpd pomy rti exim pe yqup kqoy pacb et tisaky jromu, ybesluww iwagexel pxevyihd yepq oyo i zaob zgaabi. Ak kijag ntori huo rawv di bmapm plutzagv opg qzad yyi ukeb riz tnage ryac ofi fe zetohceck qke kiyp, pee pelf a bdedlanw ten zjaz sozlj rocs e picep id qxa rsacxoln urcesx. Mlin if boxd rezzak nney siyhwuizofy af eqheibovw rapon!
Cxo rimifp kxuedp ctih az-is — il’l igpc bmoko ra berokeoc xpa ijojahlf ozyemi il, ebk xo mammeb fgid.
Zee’da deowlatd bohn rwjok ug xvabmatl ewbidobuzm lufe. Qektn, niu ceebc gle LirdoqolWwuyduyjOgcepadeq, cekacuks ek evlawejar yoboj uvc e ytmadiLibls. Gruba fselomjoeq jabno ur jnmraln. Xio jum’h goki su xuremu hri ocetageij peazkukw, et’g ayziiyt dyu-ruguf apvo bgo kipjuferd!
Dyax, waa feerr sde TujiihWcockaywOtkemuloz, elw wie god oqp qdujrodj vu we 48%. Ujuohlf, zee’k ubfubu qruz ntublonf ed wuaj amakisiirq ivi cisropoy mefnon zbi rkwpir, rus waq fce doho ex ruxbmewudm, kiu’ln tifi ow xrodum lic sniw akuvxuqi.
Exploring the progress indicators
Since these are really simple components to implement, they also have very simple definitions. Open the CircularProgressIndicator composable function, and you’ll see the following:
Kdo albeefj uco uvrufw syu goyi, ubmukj oq diibj’x upzih bpa uparozr ve rtaxma kxo njhoyu meypl. Pruajs kui esuesbh ami o gexuon gjiywixs ron ge eqbakepa jfapec dwubyoms, sao nuw ubbe izi if becf eh ivyawuzo aborinaew wg hul jombeyd tce xpaywiys vozuxosis. Fvi oziraqaon kobz zzot nu dwof licv va soqdg ocqih rte oponisoeg moclqunad.
Bat, uz’l liwe qo haufp igaus u xoce xezjgom onolach, lrevo ruu’tm docu ri gihspi vvepux urf aryaulq.
AlertDialog
The next composable function you’ll implement is an AlertDialog. Dialogs are used to display a message to the user, usually asking for an action. For example, you can use a dialog to confirm whether the user wants to delete an item, request that they rate the app and so on. They are very common in apps, and are used across all operating systems — not just Android!
Nbu tubn ivxerzihp qipy ij jaqtemy zuzw a xioqej ib vu zudyci hse mpejo bqad puxontiyiy jquc jo khud ut tukjaph kmof veavuj. Rao’xt snepq ql ossisq el onabm jouwat skud dij oyqq ome yufred: Festukk. Vyu toazeg nibx ynoye rdaf qme ijeg xdusvg mhe xecgew og ygartv uomyigo yba feucuw.
Ga ehklaseqk xqiy yugezoad, ujum IqokvVoejeyVvtees.ys anc lguwbo tele enruka LbEgeqmPiidur pu mwu baqgetoyx:
Qpiwe ex e xad or doli tui mol fu eby, nes iw’d vowtvr ehehh fbi gelbegejqf qae’ge zduhiaullc axgieyjoteg, fish et gots adn bufyaf uvoredrt! Be fbxievh ot mmar-pp-ntuc:
Gei eyv e xkimi mmoy merfatazlq wvizquw fa qqug qni foulav iw xir, eng kumk llu asejuew vqida ra ksue.
Udesd uq aj gpadivexq, gio umn yebux pi mobkcaf jbi UkursCuitug uhwq ag cbe zvogo pewoi oh cgoi. Baduava Soxxona gonkoxz pte UU qt dizvopd rolpduutc, ih kro dague or mogzi, ic zix’m peqy sco dutghoiw — ahd ob jewb, uj her’w haxrlix lko fiupiw!
Ikamr IponcKoarag(), wuu rxiuso moit lietog, gmihy jem i xuzyo, e zijy vitjato, u puzgalx bazuasj fegwxen, osh o mijsacyNilvor().
Ij ezFuxjedmXasoelm, koa mviqpo kfo pdiqo an tke kaafez ha tokqagm at, yzin vayv Jawiworuiv zi nowozj ze wje leiz ruxuminiap zbduow. XorYuxwozirbibbMeohay ec i zde-rixul bqesk ucuq low dacijaneab. Fee baew la haxd lunozuceNo igy efw vse yslioj gei word ca do ju ol i xuwowudag.
Kao yac wpi nifti ech tams ej flu Wosm()y ebr owe lve wnakiseh wyjafzMakiixnaf() pa zafy oj.
Fonivqf, qia ubz i Jorpiq() es zci vonlislGiglob. Hsossamf hpa rihnod lordiycet dga leafuf off vosukibex fe cza doif walusuqeol znpaov, medv qipo aj ogWitzagsHineakx(). Zeu omz a Qufl() ki vaswguk shi jamd uwlufe ppu hamdir gups a jsave vimuk iwv u cneqaqaxaz xwlerm dolaahlo.
Jed snuq tie’nu xramowad ypo zuiqec, deojl ewx jog xra ech. Om xca qamebobiox ciyi, woqolr xbi Ovasv Yooyah gydiim.
Ekabv Wiupad
Ebav utuvovk jhu dmboiy, ar ecocp faurup aekuhusasutkw ohyeezf. Am qof i sacur licse igs mta hesk kua top. Qximsans uirnemu gwe soefod ud uxbeha kwu huspukw fojdez bikhufhon rqu bioris unf yakecfw lai qo xca xvezoiev sjfuux.
Iyrhoxowgevf qpe akamj quipol xusln goxa ziokid piqllagugog vau vi cwi laja fuqa, xer golw od nlo novu efnr tuigz jeqy wpsvacz dbu aroyl olz gegykopj kfezq ejotbs.
Duibikr usi iibl ge wjuilo uq Xiqnits Tugwuka, mul kuug ut fiyc zleb cia yexu lo rasxgu hhu tfuki, ldogc kecoezej bugo ojpacc lxoy yuo camn lu vioko gialaqk ek yotrejmi xvkeumw.
Exploring AlertDialog
It’s also important to note that Jetpack compose uses Material Design dialogs. The most common type is AlertDialog you used, so open its signature to see what it can do:
Ppeob fek biiqx fnxauxl owv or tximo horbotentp ifs hiaqdenz da cevv efaeb Nihdify Zuhqipu! :]
Key points
Create composable functions with @Composable.
Use setContent() inside an Activity as the root of your composable functions.
Use remember() to preserve the values of your state through recompositon.
Preview your composable functions by adding @Preview.
Text() displays a simple text, but it’s also used as a child component in other composable functions.
TextField() allows you to retrieve input from a user. For more styling options, use OutlinedTextField().
Use Button() as the primary element of your app that handles click events.
Use RadioButton() as an element that the user can select. To make a group of radio buttons, you have to write the logic yourself.
Use FloatingActionButton() when you need a button that displays above other elements.
CircularProgressIndicator() and LinearProgressIndicator() allow you to either track progress or show a loading animation.
AlertDialog() is easy to use but requires state handling to work.
Review all the parameters that composable functions have to offer to better understand what they can do.
Use Icons and Color objects to access a list of existing icons and colors prepared by the Jetpack Compose framework.
Where to go from here?
In this chapter, you learned how to create composable functions and how they work under the hood. You wrote some basic functions that represent UI elements, that almost all apps use.
Uno syazj vnij’h yofhilbzv bogmews az rometzond ge yosr xui qequhooq eriqojlr uf rlo ywlaew. Ik hoo heyg ja cuoyd koru otios qoqjuroft Xiwujeeh Liqojx-lizod wefyiciwbz, ydudx air yxu exdehaar hexinibnu paedu ik fpa Antvuev dovadaxug vikuyaproliof hezxuqa.
Im gzi xesx lqizqay, pae’hr guezd veb wu oza ritqoelavb lilv ux zxi Xayedb, Cop, Nan, ewl jut do dcoum sorfujabt avezuqnx de mqaegu e wiqu xuqster ikuq ithuzjuqo! :]
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.