Android

How to Use Custom Fonts as Resources in Android Studio (Incl Toolbar)

In this tutorial, we will learn how to add custom fonts as resources into our Android Studio project. Unlike downloadable fonts, these local fonts are bundled with the APK and always available offline.
We will also learn how we can bundle multiple fonts together into one font-family XML file, where we can specify a fontStyle and fontWeight for each font file, and let the system apply it to a TextView automatically in accordance to its textStyle (italic or bold).
By adding the fontFamily attribute to the AppTheme instead of a single TextView, we can apply a font application-wide, and by using it on a Toolbar theme, we can change the font of the Toolbar specifically.
We can also change the font of a TextView dynamically in Java code, by creating a Typeface object with getResources().getFont() or the ResourcesCompat compatibility version, and applying this Typeface to a TextView with setTypeface.
Custom fonts are backward compatible down to API level 16 over the AppCompat support library. On API 28 and higher, we can specify the font weight directly over the Typeface.create method or the textFontWeight XML attribute.
Supported font resources are ttf and otf files. We can access the free Google Fonts library directly over the Android Studio Design Editor.

Example code:
https://gist.github.com/codinginflow/02d13ef838603d9bc486d446f5111653

____________________
💻 Find the BEST programming tutorials on TutHub:
https://tuthub.io

⭐ Get my MVVM Caching Course now:
https://codinginflow.com/caching

❗ Subscribe to the channel:
https://www.youtube.com/c/codinginflo…

📨 Subscribe to the Coding in Flow newsletter:
https://codinginflow.com/newsletter

❓ Join our free developer community:
https://discord.gg/TSnMvmc

📣 Follow Coding in Flow on other sites:
Facebook: https://www.facebook.com/codinginflow
Instagram: https://www.instagram.com/codinginflow
TikTok: https://www.tiktok.com/@codinginflow
Twitter: https://twitter.com/codinginflow
Github: https://github.com/codinginflow

💰 Business requests, sponsoring, etc.: info@codinginflow.com

Views :88530
android studio

Source by Coding in Flow

Mourad ELGORMA

Fondateur de summarynetworks, passionné des nouvelles technologies et des métiers de Réseautique , Master en réseaux et système de télécommunications. ,j’ai affaire à Pascal, Delphi, Java, MATLAB, php …Connaissance du protocole TCP / IP, des applications Ethernet, des WLAN …Planification, installation et dépannage de problèmes de réseau informatique……Installez, configurez et dépannez les périphériques Cisco IOS. Surveillez les performances du réseau et isolez les défaillances du réseau. VLANs, protocoles de routage (RIPv2, EIGRP, OSPF.)…..Manipuler des systèmes embarqués (matériel et logiciel ex: Beaglebone Black)…Linux (Ubuntu, kali, serveur Mandriva Fedora, …). Microsoft (Windows, Windows Server 2003). ……Paquet tracer, GNS3, VMware Workstation, Virtual Box, Filezilla (client / serveur), EasyPhp, serveur Wamp,Le système de gestion WORDPRESS………Installation des caméras de surveillance ( technologie hikvision DVR………..). ,

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *