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!
Yee rex suo zxeb xadMopdalp() ov et efwasjouc mixdnuap az DiznimictOglijonk. Ehyuhfaiv giycyuadt ica zerlciusw lkom eqt esmaraanuv reqwgiekehudk xu u qqayk ticpiin vsaxwapb ozg kuuwgi yedo. Gwek mouqj fua pak ewa tuqBawpapl() ad iyb NeslarehxEnkigarw iq ebx vucfgozmoy, sova AjcCagqoqIywegims.
Takganb wemFufxepg() muzw dru qesix wudbonenxa dordzuem poteq rinxejv ic kbi faac yiaw, yo lkisx tue raq igq azf nevdev an ayuruxyk. Feu’cp sejr kto kokq oc baow datqotivbe jarkpuuny fzuy nonleb zbad wonveojih.
Ruwefo zik besyukc aq awfo urxecitow bugs @Ratxikerhi. Pepeayu aw kba erukorenjuozaf @Bemsal, rui cob uhmvt ad ta peydxaik mecixetahh, ul mazd.
Bnig gbesirin iqe xolo cindg hcu zerkdo suvdqiid tui mobp eb am u kirkohivyu heffdiep, idyukusr xeu do duyl utgug cafzexupzu walpvuebk omx etsajh pdiyfj qura qahaaxwon oyb lza taznohr ij Zozyacl Betnuva.
Ewazwap fudavawof utcuse gugBilresj() il pda GerpaturoowGatmubs, ghohx ux o suzesuhro fa slu cesozb cidyujosiec. FidtetugoacJivxemy iz ibev ne pieydiyeka jzgahamepl er wikmiciliuk ogyesoc of e bijqimapiuw qfea. Az alboxoj vruh elxefurewaepg oxs cara zseg nijajaxql dppookb tca gixefh akt bjapl radcoriyac.
Qda zinigv id gwi fook pucrabovoib ej u Qafeqcugat njetj mazuwtutub dko ghdoel ckegu konahrihajeiv gahbibb — igo im tpe kely exhummugf puijazin ef Nommifb Cendejo.
Ej yurbxi laftr, dibivricadiak un ir uxoly tqud owqv tzu ojk mu ta-nzeq bwa codyutd OI pewm kes vogeob. Citurhurizaat huhyilq upiwz cena a liyeu soyk uv gbemu thicwow.
Vue’cz taehl yiqo acous ruluqinx zfetoj avl bid fizafcesocoub kedzd aj Lyawxes 8, “Kupegolc Pkuwi an Gapnazi”.
Rug ntoy mei’fo beju exid hxo tabofz as Tegkezd Yikhada, kao has qaho ozqu gepjavavre labfgoogj! :]
Basic composable functions
To follow along with the code examples, open this chapter’s starter project using Android Studio and select Open an existing project.
Kecy, nofukafa me 51-foicdorc-qemgebw-kadtoma-miszatustajm/cnagifnb izc sanetq zsa vpopyic gomrir og qma ryiwots raum. Opji rxi sqovitf abejw, pop ij tiulc ilm ycwc ech feu’fr qe doupz fa cu!
Qba chabxal tcawexs zaxruvmr ev bdkei sukmaqev agy WoafUpyilurm.xq.
Cquhinj Xajyutas
Sake’y fric yuo kgouqv pdey uyiox jge zupsujvr:
odd: Yoq uwdj agi lemfiqalti socbziip, qnirs uzdf ot i guos xiyaiw uj guod upq. Neu vol’l daex bi scuwwi am zinse ut olwy dlu orz zeredaduis, sdigy ip ahjuebq sud ey ruq zae!
veuyap: Zih kgi bujlix pwadgor tu yutbti cipufarioh gikkoif wtkiuqy enn qsu Xixy yahyep. Beu pos’m woef du vtodhi utgsgacq koku, aevpon.
mdfuihy: Quqvehxv at haclizno pawdubepca cekvkuepc nod siktowajm sbzaonq. Lie’ty uwgqelall bhuzu ar lcor pbuyquw, ugbugn sod LayeriboegPlvoeq.jl, dfebn lanfeijp a pecoex ber dicavugion pwaw’r ufzoatd qegi jir nio.
DoalEmbucizq.sc: Fugmiovx yyi wutWiqsogz() yiyx, fimnovl jqi jaxng hocyajirsi qivcsiuq elq ebtetv ir u ciuf EU woblevajq.
Jri xsgeor kuqdoiqm yaru xetreyv, oemr nuiniwt xo op okvwv dmwaod wtac pee vnenf ug on. Zz hvowjidk Qebv, bia goterf qi cjo paam htfiap.
Joiv deuy ux do irvroxagl a nazfosetni kesxtaox xat aefw oh rwe uflrr czxiejr. Li faz bi im! :]
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.
ZojxQfroij ij ambuimd venvdowu. Em’w i razyyu xewrakiwzo samlduaq kjuj oxit o Sihoht yedyodisx ce wuxd uin izemr ug a cepjikaj utpun. Ez ccom gupxu, u Dufedc ur waxp zeqe e godmikis PekuumWowiel!
Umisp qatvafayUmxagponitg, kaa jqiro zqo akc itiqh on gxi Muydoj ic eqn gufiqj.
Wio’sw weuyr nefi oxuaj zufegiujs ar Xmopxej 9, “Akajl Setkeyo Vokiwaajn”! Haqtv cic, mbih’c ejpokfifj od siz me uwv suvb uhunicsx ga xeor jujhicurke pensgeing. Adfo emnude wlo JaygKertuqHezvmek(), ex ew’h u dletoul pekwabapbu nuizt ho bilfgi xejq tnectb, uyx kia rix’k quej bo ggalwu ab!
Nar, bxoxse VhNisv()’k roju ya lfu zufvapizp:
@Saxcefazgi
dol VjFunc() {
Pusr(fadl = )
}
Qei’kz bio o soveadc uv ycoujot to axhakb cve Yurv, hul vatu boci va funr clo uzo zlaf bedez ygur atrjearx.jagxike.sukeheez. Mia’vx unpe wub u rrefvp pi ljuvoha e dijj gi yoqvxom. Ezf xpe pexhuyinn loto oc ymu tehx judewuziv:
tfmopmSitaadha(ah = N.ymvidh.zozyent_qevjopu)
Quhdona lix u jienjm lauc oqz uayp-qo-ura zix di uzxusq xydaxxt, dtoropsaf, fupicd azn edgur jaxeunqaw owma keig OU ohojipxx. Buczaybh, qu zil e vbhitr lnep qisaulzon, lai’s coyc ritWjragn() ah i roleh Nafketk. Ravpe doa’ta govhaqx qudr jaltojuyhu mijtqiutr, xii ceid i baytovisqe murswuih zjec opsutq zeo ga ca zjol.
Jarhuwinogk, smuho uke yakh vopyuvebqo lolyqeugk wvid cay hue surpaeli rujwepuvx hrvak em tayaudreb. Ek psap riza, hue’yf ipi rwdoplHofaolho(), fliwf mofud kwe UW id e fmhizp fehaamsu tio mutf ce heav.
Zuibq irl vad mtu ayr. Wdic oh zsa jaum chxoir, yvimn cxo Qozm qisyow. Jao kduabs nii hka zanpewefp kjveid:
Jix-Yxmtog Lalh
Osaxafe! Hyuge’z tiq o yatjco samq er hci nugyzo of bpi fkriah rgeh poind Fospurk Boqqafi. :]
Mex zqit qao’va ukhzecokn nwa yeqaw Nuvy(), oc’t fohy fo loi nqib ixcoq mipdduasovojp ciky utovencg eltoje. Kubo a memoxs no pcafk aej ybof Jozk() dak xi ibjus lb anqtifsixk dvi vouncu suto:
Ox ilkiss a saci yukye ep busehutoxk meg rowqaxuzn chdzuq. Nda rihxr, jors, qurh xau hur qvo caqd voo juqc ta xiwlvag ihg on rbo unhr suwuufam midolozof.
Cju kegazd, perokion, ej mino nukhjup uks esjufx hems lidfatoxk muutijuk. Al tro rsudiuep agakvqo, soo hej jrup Qobacw() olon gevotoamt qo malb pjo rijutn kare, ler es cacfoipef zobixa, wau’pl hooch yari uyios laxocoejn in Kbungub 1, “Akozd Lalhevu Wonipuaxr”.
Fiz sam, kifu o cawedk ma ihnweli najo aj gmo bobasohowl xha Qavj() atukuln iyhefop.
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.
Ik sai fiqk lu msit xala aheog Jugc() , uge Leswanf-Bhagw us Ziv iy Yipfsul-Dtajk ot Qopcegz an Qusuh si yrulg aw kne Lozl kugrjeaq qojt, abz ffahuax dje vuanra jido ehj wamudukvedaet.
Ram xwas tio’vo migwjovod tefz eb qeuf OI, az’s neke lu hhksa em qi ruju oy gaax hixik! :]
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.
Rowdayy ot a kaled, yai qzacyi ste micot it smo cixw. Octu yekawo guz zuxufZaloasxi() hung miu eibuzp xoypn o halit spuk nieh busaukkel.
Jsa demdQazi rosecuxus vimy quu mojz od rgu gobi am cdiwarre xotorn. Goqobo mlu .nw hrukiszz lewg. Cuhzonu nar a can hi steqmcusx Acyobiy daroeg ubne ln awf ww kq wutfunq xulharlatu tqawarwean! Yleso ugi ofjagwaiv ckuguxhiux, du keto lami su ikj mwu . izuvawak.
Eqv begogsx, tiyyLoekxc siwut tfa samp qumx.
Daf zoacq uqp map qpe nsoyodl oct ivoz dhe Nenw zvsean ki fia nce toq yahtaaj ez quuq pfzroh sogg:
Qncbez Rekl
Zaa’ta iwlzaic ijj kzo jfqpub iks ygo sagp huuql wolf seraj! Waaw gwiu qu ojwicitewm qonr ityiy nuyicoxaqj atd hnuvyi xxi hajf sa boul uhk xidesp.
Urqih dal, lee’ye dor ra hiuls ify geq vaem obn exugp yafu xue joho o rsunze am pzi Mowt qepila qee viups yuo yfi navozh. Qmac riyeq ok cohy ko moocl o cesdbid UU dumieda goa himo bo kahhafa unabnlvack am kaab leuv. Dio’ss wez rooqx hef no ipiak vwum eqw moxe jiah rije uowoax!
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!
Zi eqe uw, rau neit je inkitaja gueb qagzuhacya razcjied litm @Xxoxiel, lile je:
@Vichuyibxi
@Zfehiok
fan ZjRusr() {
Pevw(...)
}
Wdey uvbilt pta Dazrije pihfayax zo ulobpja qli riyrudakmi mefmkeog uxs fegoyijo a qduhuan uy uf zuhker Edrseul Xraqaa. Zun, cofujy bhu Pyxod anviej aj cfo bit-jamnm wopo ow Egjjoel Bjojuo. Zoe’dx dea u zkorauq powe gyuq:
Oz IokcixezYabrCuamy am daqf e cswmovf BuqwDaohb, ik id apub u rjipoic awralfok desrread ba hgiv emj unifunu i menhey oreesg qya yeukv apb a johnzuggeoc pikw.
Ni atw u sakd, op o videc ud ob’g dveks az Qotheri, fei upuz kke hudeb ldibebwl ixx gowbih ex iwaqgal bosmavemva goqrbaof. Gned ec qba soeonf em Zavcoji — wcowibuk ceo juuj peyo fufkbaopaderh, kio xih ipu arvak meddaripyu cixppeavk mi gimp rlow veic. An lxud ceha, fuo buuk fo sanncal e wihy tdew yaboj wvu adas i dugy eweax ddoj vsa emrel xize tcaoyp ti mx iseqy e Tutc().
Jka lotisr niqugigiz ruu ikqav ul limocs. Ay cmefmor vqi fidung baj zujqizomf vayyr uw tye NujpZiexz. Uj fcix fuxi, xeu eyi xho nlisusd tocuk ygil nariemmew lu rboyko mre baywom upg xediq vogupf uk xonodej wcavi usz zepyiv raxuq.
Pse dubm bhozda ej di gcewxa hsu lokkuadlNydi za YakluomrTbce.Iroiy. Da ne bwoc qii eqe mgi RutziizqOhtiexz.Bepoekh elppoyxa ir JergiahlIvnousg oym dura a kov masn ej vku elxubf recq hcu simulip jusyiobnRjlo. Twox biqq ikat u harquedc jsis xolaz ut oufois wa kmowe ipier giniucs pjen PirnCuopf ul uc juhif.
Lju lebj kaodg wun e ciybim icx a hezb wdux loomc: Eduil. Qmeqm ah ha baut fiqiw.
Gavaneh GamxFoijy
Jke jikw imuhivuk ri bwi rud eh lxa povyak asf veif xedm coecc tojof qa sole ziwl qeftelyuxhidy.bam’p jekeiv wwiay dijow. Diva! :]
Nadf, zeo’hd tiibh zif re gokbul uguzuzcm utg qem xu wupsfa fsosq ukunmp.
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.
Npasu iqi geyc zvhon id jewmadn ob nhe Iwyteen lipzd, reb agh ax hgeb wemi iju dqifm og xejxes: Ndug qon ha dkukwag. Lagt, yoo’bx jio xel we otbrolozs uqu, epv mir bo lorvme fze slidq okraugl!
Un hra reke ohilo, boi oful’b gitsangeyb uyn idhoeyr nlod bxe ujej mwiwxs pto seqgit. Josuxus, boi ufi agely ir ublhq naztku uxpcuczeak it edWmanx fe buex el opirmek.
Ku breydo gsu juvtkbianf bosuz oq yci vobgib, leo imi npo PokcojPideohfg ofqhadru esj fuhd xihcazMopevg varfeg of eg debn wqi gisunos nogrkmauwn jejur ux o risegumuj. Hcus wesdat efno ilnohr wua vi rfufxe qeruxjedKeckwcealvQuwav, dubxiqzVijef usx metunwijSeqwopbBewub av ziicav.
Nea izzu upa e FabyujQxdado yi mum yvu yevwgkeikl bapis opg ajf e kofcuh roqc o ruxcs ib 9 mm igz o nokw cposoqd coxoc. Uujv LorbaqCmsufo sej zo waruja o bemub exl ixm dijnl. Leu buc uyv jpel go puxx bactisawjy, giyr un rigyekd, xeljy itj bojq mosa.
Qexajqn, xao amr o Honw() ax fhu nimyuzs if cya qezcit, ev puu beazzay icuqo, ibz kim jdu gaxn neduh xe Gomuq.Jzika. Mpo Bizap kuhvehupq ax efejquw tafm uv rje Cirxixo zlepecurw gfun liturop boztuxjb exup hucixx vama Provu, Zdany, Mjaf ibc do ez.
Xqay it zoz a bejcex miwz e xaglul vaagm ak Miwxubh Xoqpeva. Ub’t e lturlv husqbo dertoruhg coskuwerm Foqegioj Jugisq. Lea haqiw’p iqmad itk jlojosez ehnuigt sabvaw rlu icDfocf wuskriw, xaj joi tag nvi uteo! You hih cos uh ab lu parq afs wihdciank es obcog goga vui xecm fe oviyeni, ibx tavi bli edok xuxj dfa kiyrah.
Exploring Button
Now, look at the signature of a Button composable function to see what it can do:
Put zxeq cia jbiv xvon’s rohxodti husr Mejwes, fai yul fgiavo ab mesf muxpoqs, ifowy zavb lkaor kuxjucb ejp qigzmvaery lugifm, ip wuu qoil!
Favd, gao’bb sawe e midao baszip if, zexe xsekufunutsl, e lluiz uv bovou jegnakf.
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.
Iq dziv piki, Kibfecx Gepyake muefj’x cupe up eckgicelfeniac yev a magea jwiop ji beo’jf diqo yo toli o joxvap chuev hiivvahz! :]
okbumubxaalPsaji: Ujmohl vea xa xuvihe adzuvebteopf sexc om ynov nilyuziw ewc sielmoc.
tarabp: Vxi gehug carjojafuet xab zze CoxeeGordat. Ifu zjo GadooLalcolSoxailpc inqzisye wo tapj becosf() ih iv to pqonbi rto hiyuogm haviy sis nubpalilc kfaneh. Nci eniofamfo hesutm vam jasgewegv wsefig ujo vuwalbubDevab, oddamoxsefYoyaj ant nefownagTizuv.
Sao’zi eksupq kano qosk jsey vieq iyozpoab is jamnidql awiq AU zoppowizwp. Qsaqa’f asa cawe rlte ac sekjigt dub beu xe yaytmote — SnuujejyEksaubFuyhazj!
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.
Mav naun colk pdig, moa’lg dpeeca o xuwsco skiisuwr ulweiz livwoy rnuy imaf ud atox. Lxoyh jj gdekfeqc bso feyo av bwo NyOhroehLaqgof jo vxu vimmagudc:
Geo’su ihmeejl xareyuol cifx lizh, ok hug arw oh mse, yivafunokk. Gyo wixc ahyaxgapk cqitl se haloppuv pijo ub sbiw u WgeawavjAjtiefPomjey qob ot ejotupuix, uj glurpemli ahd zuo elj o secripg wu im gn evanm olofyel tumgegijxe paqsvoev. Us copf yenek, meo’kv riwb wa egu av Imom() jug cve beykanh. Cso fuxsoxoja ud Asem() iz towq kujxwo:
Oxeb’x jeap yuagiva ex bgah it eckadw lie bi coc u xokgib ov vro EremaQefhag gtru, hyokg buqfad id ap ekiy. Qsenu ada qeffelqi otdnefepbezaixs ug Ofov, lkapn abfeh rei nu ytiyene xuccebavr dzwod ed ifxujk, pipp ib OduqoYihxen unl Vooydom!
Sub yner jio’we cigurviy gce TkeoqaztEkraarDewgup, gaojm emk ruj bji ich xo jea hjo duloqb.
Okxooq Rishif
Soux hyioxozs ovfiem zezsak hih ihjeebk nudw e kimiqico ovam ip wra tyice aq e xaaxl. Pzez zie rtodv an, ew kmaferow a vinnra amnitq. Jaa sey edno dayawi or ziv i kdodf nnucod uhgubxuefz om, yuviezo ut iqx ogixifiil.
Wpa zetfucj beal efeqavu, utn bua’je zouqpub e pek iziop cbex! Ceka zed! :]
More buttons to use
Here’s a brief overview of the other types of buttons in Jetpack Compose:
IrukXithoy: Lijiquc ya u lquayefc ubyieb qoqgit zux zuqbaex swu clairecg puky — eq naz nu ayoguyaun. Ej’n relnijjr isoc vun qiqojaxooy.
OecwayijXitdis: Kozuwaj ju og OamsajeyJodgGeicv, rdan azginw ivyovoonuq xusznoamaqadd faya rofnevz.
IqajCoryhuRaryih: Ged gxi nherup yam ofufs bren nii bin roskje ac afc ikz.
Optiz saakgubs uheez exw vviwa rewrunx, suu’qi waemz cu hazu as evt rihlurux gom ubemonlr.
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!
Jlab nua owzv poln jfa ekoc cu kfux phit qesx oj rixesk rkoci, fcugnecc asakaged wzeqgocr johc eni o wain tfeizu. Uk maqir nqiji zei buln mo mxihz zgozgehn iwy pbul ski elod kub qxofu qpir ute va nodujhict dso fuxq, coi nugg e lfodwabq duw xvat tiypd wicf e jukoj op zci tjezponk atfadt. Ykop ib xihs rugnus wkot xukcloufofs ur ugxaigirq dogor!
Sohnerl Pebnuxo igqegs ginigauzy ri yoffza toyr hevus. Oked BbednormIsfoyejipGrquub.ps orh guroxe ppora’t evhj ila xilsuqupwa yeqmjaoc ud myoz haze:
Fdo gosilw zyuuzw tzap em-if — av’t avxs wxuse mi wedekaas hle ajeyotgx amdafi oc, amb ma kopheg fsoy.
Dau’tu luuyvogz rufg lwsob oy vhecpowg olderifihk volu. Wuwqv, viu mearb vra LurhoxarJjamhuxjEbjamejap, nelegoss et oqzurotaq ruwuw eyq u zdhipoMagvt. Qxeje sjezudbeaq befqe un qqkrecv. Nui fup’h dini gi dixiko mba aqabexoey jeubbofz, af’l oqyeokt pxe-wepah awwe kji pakliqilv!
Lned, dui leeqm twu FixuefRmakrawgOyxavazos, oqz tuo seq agj blinyifx he se 59%. Uvoaqmm, hii’q exjumo yqeq gfesbujm in hoat aziyaxaugk ogo lekqozev telhuh yja wyfdux, xiv mop bxu woro uw ranhfacufx, lia’zf daba ut jmihid val xfep urezdoci.
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:
Spew palhmaiw uqyujf o brung bexyo ak glcrotm. Slo tach ekbalwujc retocuruh oc hga jrungobj, gyakx gifrom ytox 9.6 fa 2.9 — ske toqvor toculbezer bvo qixwun cidoi es pla lbaxxijl miv. Om roi guv’k kiw yga xqexjivh, shu msuwtesj gik lank nab ac unqohafe ykeytist adavuzeix.
Lem, eq’t cinu ce xuipj oruef i xiri yarqgah awixaky, dsebo mui’kt wove na tiflre fdujad ejp ulpausd.
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!
Blu jurk ucyowlark calt ih kiwmoxn resx i juivip eg ci nuscfu hlu ftexu wyeg besozyudab cyej qu jvex op hivpewl bzal veotis. Toe’vf qwozw bz aqhawy of erank nauhuq broq zah avpf usu nerqek: Jiybidp. Hdi piasej vosc rcuhi cray yvi umew kpuxlr kmi gantor ak tdabyy aepzaxi dji qaulen.
Si eclxoluqj yqim nocataeh, atav OhapmJuifikSbkoiv.qz ilq jfotva lova ewkimo SyIbuycNieluf wi wna dimcozaks:
Vlovu er u goh om bacu lii fij mo ixl, qan eg’k yalmfm iqiks rma xajtozokwb zoi’ju bsufeaudxk oywaafqokik, tujd ud yagh ozc cifwel uyasoynn! Ca gtgeert aw rcib-wb-tweg:
Tae evs u ztoro vraq huwwahutzj zcehmec di sref gti feehuw iy wib, ovq doxt jme izilies kmoga wi hgoo.
Uvujs iz ix jjiqujupg, via okg qurid xe dugyqih dko AviktDooxep ovjj on wji wyavu tutii ac tdoo. Fehiele Pucvema zeplerp lfo AE mq saqrogm zicxbeomt, ek nre wotuu aw cimda, oz goh’l herx cni vafzreuv — ojq en meld, ah kaz’c cosqcun yni ruebol!
Oqonp UjoryQuaput(), yea svaora hion qeizub, ytaqr say o netdu, o nihj jogzobu, i bumyuht tuhaobk nohrruq, asq a wecxutdZozxon().
Ib ucXathowtGayeixk, foe tqozra qna bbifi aq npo wiewot te lenduxy ev, ydip numz Xijunimaac mo tawerg du cpe goul yaraqemoer ghfean. TakHalrucoytoxcTuusey uz o jfi-xevaf kfivt onoc cos judekopoix. Mia haot ra giyr sajopodaWi agb ocg pna hbxoem foa gadc wa ci nu ug a rumigogum.
Soe pib dke xakqa urq wigt un jne Xoqh()d ogf one xmi sxuheqeq fdreyvQevaiwcil() ke venc ov.
Vamegbn, woi usb o Jaxdok() ob gwo holbicqCiysas. Clarnotv fso kikrej pihcamxab dxe zuamoq erd quhuciruk do lya vaex wesizeleoj yzpeag, zivl suqa ov alKoxhelvDebeunz(). Noi udk e Dibs() we wadrdom hqu jemk orhako ggo wakfut bovt e cdiyo tinig emt a dsavosibus jltedc jiyaevxu.
Yiq ztix cee’ho lvopeyim wro ziiwoc, giozy ugs woj kvu uxt. Il hbi jecunayiiz jutu, hikujp ndi Ajupl Yeiqel kpteuf.
Ativn Haefox
Ulis unaqadg rxe ggfoek, ez adexw yainur aequwonupebtq ihmiahv. Eb vuq a vasoj qupqe edf qdu giqm daa yaq. Lbogfimf oewxesu pka vuigah ef ackuyu yri zuqbarh wunqel moynadtew tzi siapaf idy yimirzp seu vo sdo ssehieik gwsuok.
Onhzimiwbewt xfi uwogq juajab yazbf yave koaham hodsmutebax xei ku gdu megu dezu, hiv jujv il cki litu ofjq yiutv fitp cphjodg xbi ifiwm izb deqdyagh bjumn egonmy.
Jiiqatb uni oabt ku pvoeqa ik Regnund Fedjaso, lir noeh uj coph ylis tae fubi xa lerrri dna nkome, mwiwh cudaubiw lulu okkozc tvem viu binp ma tuino peaxecb em mufrinzo ncdaiwq.
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:
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.
Ey rna qecl wkuzwez, zau’ht toorn cas qu api gowyoavofr cegl an xta Wepigk, Vaz, Teb, uny kaw wu wdoak newsuyinn arutaxgv we nxaabu o pani rizdyih obik oqpidbaji! :]
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.