How to change the font on the TextView?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Changing the font on an Android TextView is easy once you choose where the font should live. For modern apps, the cleanest approach is to place the font in res/font and reference it from XML or load it through ResourcesCompat in code.
Use res/font for Modern Android Projects
Put a font file such as lora_regular.ttf or inter_bold.otf in app/src/main/res/font/. Once the file is there, you can reference it directly in XML:
This is the simplest solution because the font becomes part of the normal Android resource system.
Set the Font Programmatically
If you need to change the font in code, load it and assign the resulting Typeface:
This is useful when the font depends on user preferences, theme, or runtime state.
Built-In Families Are Also an Option
If you do not need a custom file, Android already provides built-in font families. In XML:
This is quick and keeps APK size down, but it gives you less control over branding and design.
Applying the Same Font to Many Views
If several text elements should share the same look, define a style:
Then apply it:
This avoids repeating font configuration throughout the layout files.
Avoid the Old assets Pattern Unless You Need It
Older tutorials often load fonts from assets/fonts with Typeface.createFromAsset(...). That still works, but res/font is better integrated with Android resources and is usually easier to maintain.
Legacy approach:
Use this only if you are maintaining an older codebase that already follows the assets-based pattern.
Theme-Level Consistency
If the app uses the same font family across many screens, consider applying it through styles and themes rather than setting it view by view. That keeps typography consistent and makes future font changes cheaper because the change lives in one place instead of being copied across layouts.
Readability Matters More Than Novelty
Custom fonts can improve branding, but they can also hurt legibility. Test:
- Small text sizes.
- Bold and normal weights.
- Different screen densities.
- Accessibility font scaling.
A decorative font may work for headings and still be a bad choice for body text. UI quality depends more on readability than novelty.
Common Pitfalls
- Putting the font file in the wrong directory and referencing it as a resource anyway.
- Using a custom font everywhere, including dense body text, without testing readability.
- Repeating font settings manually instead of using a style.
- Loading fonts from assets in new projects when
res/fontwould be simpler. - Assuming all font weights exist when only one actual font file was added.
Summary
- For modern Android apps, store custom fonts in
res/font. - Use
android:fontFamilyin XML for the simplest setup. - Use
ResourcesCompat.getFont()when the font must be chosen in code. - Shared styles keep font usage consistent across the app.
- Prefer readable fonts and test them at real sizes and accessibility scales.

