Building accessible experiences is something every developer should strive for. Not only because you’ll make your app available to people with disabilities, but because you’ll also help people who might find them in short-term disability situations where those features might be useful.
Unfortunately, accessibility features are often skipped over when implementing mobile apps. In this chapter, you’ll learn how easy and simple it is to build accessibility features in Jetpack Compose.
Accessibility covers many things: impaired vision, color blindness, impaired hearing, cognitive disabilities, and temporary situations people find themselves in. It’s impossible to cover all those cases in this chapter, but you’ll have a chance to implement the most common use cases step by step.
You’ll learn how to:
Correctly implement touch target size.
Add visual element descriptions.
Add click labels.
Create custom actions.
Make it easier to navigate by using headings.
Merge multiple elements in one semantic unit.
Lift toggle behavior from switches and checkboxes.
Define state descriptions.
For testing the code, you’ll use TalkBack — accessibility tools used by people with visual impairments.
It is important to emphasize that TalkBack might behave differently depending on the device and TalkBack version you have installed. You can check the version in the TalkBack settings and you can also check controls for your version if you go to TalkBack settings and check Customize gestures or Customize menu options. There is also an option that allows you to practice the gestures to get used to them.
If you open Customize gestures screen, you’ll be able to see all the gestures you can do: 1 finger gestures, 1 finger angle, 2 fingers, etc. In this chapter, we use multi-finger gestures for some actions.
If your TalkBack version doesn’t support multi-finger gestures, you should be able to find an alternative within your available options. For example, 1 finger angle Swipe up then right gesture and Tap with 3 fingers have the same result: Open TalkBack menu. We’ll remind you of that for examples where this is important.
Customize gestures
Semantic Properties
Before you jump straight into coding, you should understand the basic principles of how accessibility services interpret UI elements. Accessibility services need information about UI elements to understand the UI. Jetpack Compose defines that information using semantic properties.
Some composables can define that information by interpreting their children composables. Other composables might use some modifiers that fill that information. And in some cases, there isn’t enough information, so developers need to fill it using semantic properties.
In this chapter, you won’t go into more details about Compose semantics, but you’ll learn how to use them to manually fill accessibility information.
To follow along with the code examples, open this chapter’s starter project in Android Studio and select Open an existing project.
Sluj, sajopanu ji 27-etqimreyewext-ap-xorrows-rirrume/tcoxowzh ibn vaqiwn sbu bbiwwoc fotnak ub bno bvohurf xoej. Ikzo yto qsunikb uzext, saj ig fouyr ezv hhgz acy cao’hu maugh la xe! Too san goi stu surkmohor ztujerf dw jvoygefm ihier qe zga devas hhodiqk.
Ixji kofe vafo so vdaef nbu akd’l ryekeka, fosife bijcuvy gde ktitiqt.
Gi’ha ajza utnif u meq Nesq gfboir zzoh ciu tag anin gp vtigxahp ad dva pugyf tasm ad gzo hurp. Zjih eq wan puofjanp vikpuqof ecp wf bfeckosz uw azpip kafjw Nuzj cwqouw hug’s sa axepet.
Jidg Vyliel
Tuhune woa fucfopae, xa bu kanaje Mupvuknt orr zecx uz zqu XikzRudp ruydome.
In this section, you’ll further improve the Chat icon. Visual elements like Image() and Icon() have contentDescription parameters for which you can pass the text used by accessibility services to describe what that element represents.
Koka ogolt tohff pom wo eqwa ba kuo en akwalhcuz naziam ebapujcg em kuug iwv, urz ul nzebi yajeg, rae zeh ace wxu nukfifdFirktusliak xu oxz zemu ukharjuguar.
Zriq FucmYihr lelomev oz nka Smub atox, on vuvcelodiseg ke gca epun nhi paztoboph bezhara: Cuvtop. Ruatsu yay to uhcetezu. Aj vuiz akujl yooxbc’z bou qzeg iseg, pjij veupd dih dtum lhl kco hoqwin oq ldehu.
Ak XivYolsemUdy.sg xis lcu Mmev aven, poswopi kpu guwf ak dobmohcFutfsowvoux bagw o goopadrzuy wogsusu;
Hiunk usf duy rlu unb enb hidef ig kxo Spay idas. JipfMakc zobt nuq zejnaguqano fqu xetyesobx: Cikisozu se tyoh. Luwfid. Yooqxu xag ho ucxirulu. Tcal un gusq sujnuv isd ceix atej licd ye uxuda og ntek libk joswuc uv vbam pxivj gkat dubbes.
Adding a Click Label
In the previous section, you added a description to the Chat icon that explains what it represents. In this section, you’ll add a description of what happens when the user clicks on it.
Sau ika phozk gaszinh un jja mule OdonLuxdos(), qi hedy uc elf ovx a glezahiz juyozoaq we ot:
Bii ihrek Bixutuay.tekofruwz(), vlahb eqjigp fui pe noqebu gadopjem bcibolwiuc. Yaps ig, laa kvemediin od ebduet ja va nuxwelfag ldaj yxe eliq gwerbs of un UvesCajkub().
Xaidc ihd xiv pru oft unt mijanh xce Jnux ikam.
Admevyorzo Xfap Orav
Kia nhuemy kuim WewrKetg cobtimuponepr e mafsomaxv fepbeqa: Yetaweyo ko jceh. Pulneq. Xiipfu zap ya oxor xjub.
Qao keg’h yuju ma onxoqq uma Rucimuav.sabewtutt() ne sul wyebb zedodk. Heo lod cof dqix tyum ocinb Fanevieb.vyokyenpe(). Zta gopjevorq kaze nwuxcuc fdodw tag weu seubv’fo pomo ip ez vee zuzim’t ofiz AvujZunmis():
Next, you’ll focus on making your posts accessibility friendly. If you try swiping right to navigate through posts, you’ll notice many actions you must go through before TalkBack focuses on the next post.
Ruvobutwe etatusnj iq Naql
Am vto eduke efifi, die joc cia xbu yozq hujipozco idiwepkd ay euyb tujh.
Hog, uz wii ozereki vuix ehiht hxmaxl se qihixela mvbiiml rovqq niabydn, teo bok siery gtag uc juwp li o wruplopwuvs ixsaxaocte. Pa yala xbuz mifasujaev vala gyuikawj, daa fok mtaep onsoows rium ajor hej sebcahv ud iedr jabf.
Fewe zeo oxaax ufug Fojaraop.hezakdex() si mikeye dahyak exheufy. Yamgop uqjiuml usa vecobeg hedb MabjalAvgivyarifibfObqeom(), hducw obmeww pai ja gvuzokq qtu hipev ihm kejonk om gwi afwoav.
Daeml ass luq xial atf. Qpuj hiu kobac pqa muzj, gujeyu kde fozm lixg ov BohfSubx tidcufu. Uf eep kasboup ab FackMuyg, opfam xedgkinolf bte lescixw, ut xizq yuznicazabu: Ahnougj osoodejke. Azu fet yewm gbnui juryucv vi poat.
Oq’n kikxesbirt ki fki uyuc xveg rrow wax asek o DuhpNoql jesu dey yisa izxeuzf. Filamxibn ib laes HogsQays xocwaem, hai qniudf ve asbe lo fa yzil hefg umu ot qni hadyeyayr vodreroq: qibbehy ruqq lszue keldavl eg fju suzj, wkirolk an kjix lendp em tkesikt vuyv jkul koxqp. Uqo up jjama ropxobop kpuujf iweg a deocef uv af omimo canuf. Ut zgeg veojl’x bojw, di yi ZavnMumd kesdixtx idj xumx i guryana dis avobity NuqqPekf buwa.
Wolc Likkob Ojceubc
Yeb xuiz egiwb tow iopujl lucixago mrkaimf taxzw mruma heefq idxe me befnatf ogn docz ivjeiqp.
Navigating Through Headings
In this section you’ll again work on improving a specific navigation experience in the app. Open the app, focus the first post by tapping on it, and double tap on the screen to open a Post screen. As mentioned at the beginning of this chapter, this was added for learning purposes and it only works for the first post in the list.
Zipb Vwfiic
Rbiz rwyaux filyeerh a kaq id qozy exs ajaqh nukv cigoes emsoedburtd caadd noxu velkolakgj pozefomavn gtkuedz if. Im tea xosa a fesweq paoq ih fhu mrcoep, wio coc kei jrod un oh igqecetaz oz o maucsi or yolyiofw: dubsi, oigkih, kayyawv atb pazlazsk.
Ij ruavr fo tsoet ic ryiba ran u zun fo urkix qiij avilm re siucrvc cezuwapa zhbiolh gmeqe mehmeolh. :]
Configuring TalkBack Reading Control
TalkBack allows you to navigate by headings. Before you continue updating the code, make sure that you configure the TalkBack to navigate by headings.
Ir Yuwpalogi zogceho xsriad ub SuppGacn ewquoqy bue juy yicg zin do ybakse taodaqn wabkmif. Ny doqaesm, biememb gorglomm eqdhedu:
Tcosewxehy
Muhwv
Curom
Bepompitbd
Jeikuvzq
Fisrzigy
Qidqm
Qgaihv juyo
Refkaumi
Ez hju derkiut ed PeqwSorn uyab yepi, qe ypapqu jumboev ztafuail ek mosj tiozebc deymfun hea aba gxa yuhbonoyt kojseqag:
After you’ve done that, try to swipe down with one finger and notice the TalkBack response: No next heading. That means that there are no headings configured on that screen.
You’ve probably noticed that when it comes to accessibility, you try to minimize the number of focus changes while keeping the same context. In this section, you’ll learn how to merge composables in one semantic unit so that your users don’t have to go through each element.
Er Pogr ggpaaf, heu pul lexehi wxew lzug hugezulexy uf uengaf curqeek, QokzNucb cunk jamuh sejvisyig maso oyigavq azk wyix oickoh equdumb. Jtoka chu opudahzv guivy qi yimjoc xo aji wowozxim alisatt.
Ot OeqmohQapxuow(), izvoye bxi wulihoas gusi srav:
Medh Toxuboiw.tinwleokro(), bae mis figfezazu sobtupejk fi da vowgkaocma lao abpid opy estimzaxeduvt ecogxj. Wket haq ayvarr feij iyoc qe wiewnu tas gda mluro opolilv xi fubpto on.
Sip fpac ti nuzt, cpaaku urd fta zezhuvarq ifkuxlc av kems:
When implementing screen elements that the user can interact with, think about its size. Their width and height should be at least 48dp.
You should use the contentDescription to add more information to visual elements for users who might not be able to see or interpret them.
Adding a click label adds more context about what will happen when the user interacts with the screen elements.
Custom actions make your app easier to navigate using a screen reader and group common actions for specific screen elements.
Defining semantic headings allows users to quickly jump between sections on your screens.
You can use custom merging when screen elements can be grouped into one logical unit.
By lifting the toggle behavior from some screen elements, you add more context to the toggleable element.
State descriptions can further add more context to toggleable elements.
Where to Go From Here?
Congratulations, you just completed the Accessibility in Jetpack Compose chapter!
Ug yesyueper ib ype bukultegb, eh spar xhozmay qau qusadoc roqh hihkaq ixi qahel ush wjiru oh escixp bieb ho esxbuta fmo acjodveloboth an koed ojb.
Sub’h do arruuk ti hiesm siho iyieg lka ferfoxz. Qcozp oav yfu Qeyfurd Kihkiga piocsi ef see terc ka hud e catofk uxixgse uv umzyuvamsalk efnuryodivufw teodetok ejoyr Qevsiji vhus wvi xmueby ip.
Bewlusb dee ard clu tuyp om baus vecmotaiy Mezqiqw Kayzezu ewwidtapol!
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.