TextView
XML
Android Development
Bold Text
UI Design

TextView bold via XML file?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Setting a TextView to bold in XML is easy, but production Android apps need more than one attribute toggle. Typography should be consistent across screens, reusable via styles, and compatible with custom fonts. A solid setup treats bold text as part of design system rules, not one-off formatting.

Basic Bold Attribute in XML

For simple cases, set android:textStyle directly.

xml
1<TextView
2    android:layout_width="wrap_content"
3    android:layout_height="wrap_content"
4    android:text="Hello"
5    android:textStyle="bold" />

This works for default typefaces and straightforward layouts.

Combine with Custom Font Family

When using custom fonts, define family and style together.

xml
1<TextView
2    android:layout_width="wrap_content"
3    android:layout_height="wrap_content"
4    android:text="Title"
5    android:fontFamily="@font/roboto"
6    android:textStyle="bold" />

If font package lacks bold variant, Android may synthesize bold and visual quality can vary.

Prefer Reusable Styles

Do not repeat the same typography attributes in many layout files. Define style once and reuse.

xml
<style name="Text.BoldLabel" parent="TextAppearance.AppCompat.Body1">
    <item name="android:textStyle">bold</item>
</style>
xml
1<TextView
2    android:layout_width="wrap_content"
3    android:layout_height="wrap_content"
4    style="@style/Text.BoldLabel"
5    android:text="Reusable" />

Reusable styles keep UI consistent and easier to refactor.

Theme-Level Typography Strategy

For larger apps, place bold text appearances in theme tokens and reference them across components.

xml
<style name="TextAppearance.App.TitleBold" parent="TextAppearance.MaterialComponents.Headline6">
    <item name="android:textStyle">bold</item>
</style>

This approach supports design updates without editing many individual screens.

Programmatic Bold for Dynamic State

If bold status changes at runtime, use code-level toggle while keeping XML default.

kotlin
1import android.graphics.Typeface
2import android.widget.TextView
3
4fun updateSelection(tv: TextView, selected: Boolean) {
5    tv.setTypeface(tv.typeface, if (selected) Typeface.BOLD else Typeface.NORMAL)
6}

Keep this logic centralized to avoid inconsistent behavior across fragments and activities.

Accessibility and Readability

Bold should indicate semantic emphasis, not replace hierarchy. Also ensure contrast and text size meet accessibility needs.

Guidelines:

  • Do not rely on bold alone for critical status.
  • Combine with labels or icons for meaning.
  • Test with long localized strings.

Good typography is both visual and semantic.

Device and Font Compatibility Testing

Font rendering differs across OEM devices and Android versions. Test key screens on representative devices when typography is brand-sensitive.

Include regression checks for:

  • Custom font fallback.
  • Bold rendering in dark and light themes.
  • Truncation behavior with long text.

Early testing prevents subtle style regressions in release builds.

Compose and Legacy View Coexistence

If project mixes XML views and Jetpack Compose, align typography tokens between both systems. Inconsistent bold rules across UI stacks creates visible fragmentation.

Define one design token source and map it into XML styles and Compose text styles.

This keeps app-wide typography coherent during migration.

Preview and Regression Validation

Use layout previews and screenshot tests to verify bold hierarchy remains consistent after theme changes.

xml
1<!-- preview-only sample -->
2<TextView
3    android:layout_width=\"wrap_content\"
4    android:layout_height=\"wrap_content\"
5    android:text=\"Preview Bold Title\"
6    style=\"@style/Text.BoldLabel\" />

Visual regression checks are especially useful when design tokens or font assets change across releases.

Material Components Consistency

If your app uses Material Components, align bold text with existing TextAppearance roles rather than inventing separate ad hoc styles. This improves consistency across dialogs, lists, and app bars and reduces design drift during theme updates.

Common Pitfalls

  • Hardcoding bold attributes repeatedly instead of reusable styles.
  • Assuming custom fonts include proper bold variants.
  • Overusing bold and flattening visual hierarchy.
  • Applying runtime style changes in many scattered locations.
  • Ignoring localization and accessibility impact on emphasized text.

Summary

  • Use android:textStyle="bold" for simple cases.
  • Prefer shared styles and text appearance tokens for consistency.
  • Verify custom font bold support on real devices.
  • Keep runtime bold changes centralized and intentional.
  • Treat typography decisions as part of accessibility and design system.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.