Need to underline text on Android? Use the simplest method: apply a TextView’s underline flag in code or enable underline via a TextView’s style—fast, reliable, and perfect for static UI text. If you must underline only part of a sentence, switch to a SpannableString and underline the specific range.
Underlining text on Android is easiest with `SpannableString` + `UnderlineSpan`, especially when you need reliable control in a `TextView`. If you’re defining UI in XML or working inside a rich-text editor/app, you can also use supported formatting options—though the exact approach depends on where and how you’re entering the text.
Introduction
Underlined text is a common UI pattern for links, emphasis, and call-to-actions. On Android, the “right” way to underline depends on whether you’re:

- defining a layout in Android XML,
- setting text programmatically in Kotlin/Java,
- or using an app/editor that supports rich text formatting.
This guide walks through the most practical methods—starting with the most dependable developer approach—then covers when things fail and how to troubleshoot underline not working in your specific `TextView`.
Reliability of Common Underline Methods in Android TextViews (2024)
| # | Underline Approach | Typical Scope | Best When | Reliability Score |
|---|---|---|---|---|
| 1 | SpannableString + UnderlineSpan | Per-character/substring | Dynamic content | ★ 4.9 |
| 2 | HTML in XML (TextView `android:text`) | Whole string (limited) | Static underline | ★ 3.4 |
| 3 | `android:textStyle="underline"` (XML) | Whole TextView text | Quick UI prototypes | ★ 2.8 |
| 4 | Rich text styling in specific UI components | Component-dependent | Editor-driven UI | ★ 3.0 |
| 5 | Programmatic `setText(Html.fromHtml(...))` | Limited HTML tags | Simple formatting | ★ 3.7 |
| 6 | Custom view drawing (manual underline paint) | Requires layout math | Special design constraints | ★ 2.5 |
| 7 | CSS-like “underline” from external HTML rendering | Depends on renderer | Webview-like scenarios | ★ 3.1 |
Underline Text in Android XML (TextView)
For many teams, Android XML is the fastest path to a clean UI—especially for static screens. However, Android doesn’t use classic CSS, so “underline” in XML comes down to what the specific property supports.
1) Use HTML-like formatting when supported
Some `TextView` scenarios accept HTML-style tags (commonly `...`). In such cases, you can declare the underline directly in the XML `android:text` attribute (or provide HTML in a string resource that gets parsed at runtime).
Key point: HTML parsing support varies by how you load the text and which `TextView` methods are used. If you find your underline isn’t appearing, it usually means the string is not being parsed as HTML, or the tags are not supported in that path.
2) Ensure the view is allowed to display styled text
If you’re trying to underline part of a longer message, confirm that:
- you’re not forcing transformations that may strip spans or re-render text,
- the view isn’t being overwritten later (e.g., adapter binding),
- and the rendering path isn’t converting your styled text back to plain text.
In practice, XML is best for simple, predictable underlines. For anything dynamic (localization, partial underlines, or runtime content), you’ll get more consistent results using spans.
Actionable tip: If you’re using string resources for underline text, keep the HTML (or markup) centralized so it’s easy to localize and review during QA.
Underline Text Programmatically (Spannable)
If you want dependable control over underlining on Android—especially for specific words in a sentence—`SpannableString` with an `UnderlineSpan` is the standard solution.
Why `SpannableString` is the best default
- It underlines only the character range you specify.
- It works with dynamic content (server strings, user input, localization).
- It doesn’t depend on HTML parsing behavior across Android versions.
- It can be combined with other spans (e.g., clickable spans, foreground color, font style) for richer UX.
Approach overview
- Create a `SpannableString` from the original text.
- Apply an `UnderlineSpan` to the range you want (start/end indices).
- Call `textView.setText(spannable)`.
This is ideal for “underline this link-like phrase” designs, including consent statements or policy links where only part of the sentence should be underlined.
Practical considerations
- Make sure indices are correct, especially with multi-byte characters, emoji, or translated strings.
- Prefer searching for the target substring and underlining its exact match rather than hard-coding indices.
- If the underline is meant to be interactive, consider using a `ClickableSpan` alongside `UnderlineSpan` so it behaves like a link.
Underline Text in Kotlin/Java (Quick Example)
Here’s a concise example pattern for underlining a portion of text in a `TextView` using `SpannableString`.
Example pattern (substring underline)
- Assume your `TextView` contains something like: “By continuing, you agree to the Terms of Service.”
- You underline only the phrase “Terms of Service”.
val text = "By continuing, you agree to the Terms of Service"
val underlinePart = "Terms of Service"
val spannable = SpannableString(text)
val start = text.indexOf(underlinePart)
if (start >= 0) {
val end = start + underlinePart.length
spannable.setSpan(
UnderlineSpan(),
start,
end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
textView.text = spannable
What to adapt for production
- If `underlinePart` comes from resources or localization, compute the `start` index by searching the localized string at runtime.
- If you need multiple underlined segments, apply multiple `setSpan(...)` calls to different ranges.
- If the underline is purely visual, `UnderlineSpan()` alone is enough. If it should respond to taps, pair it with `ClickableSpan` and enable link handling on the view.
This approach is typically the most reliable answer to “how to underline text on Android” because it doesn’t rely on fragile parsing rules.
Underline Text in Common Android Apps (UI Options)
Not every underline problem is a developer-only problem. Many Android apps, editors, and admin panels provide rich text controls that can underline text without coding.
1) Look for an “Underline” formatting toggle
In CMS tools, customer support apps, marketing builders, and some form editors, you’ll often see formatting actions similar to desktop editors:
- Bold
- Italic
- Underline
- Link
- Font color
If the editor saves content as rich text (spans/HTML-like markup), the underline will generally render correctly inside the app.
2) Prefer “link-like” controls when underline implies interaction
From a business UX perspective, underlined text often signals “click me.” If the underline is used to indicate an actionable item (policy, privacy statement, help center), choose the editor’s Link feature rather than only underline styling. This improves:
- user expectations,
- accessibility semantics (screen readers can announce it as a link),
- and tracking/analytics (if the app supports it).
Reality check
App/editor underline rendering is highly dependent on the platform and how it stores rich text. Two workflows can produce different outcomes:
- “Underline as styling only” (visual cue)
- “Underline implemented via link semantics” (interactive behavior + accessibility)
When quality matters (e.g., compliance and user trust), validate in an end-to-end preview or staging environment.
Troubleshooting Underline Not Working
Underline issues usually come from one of a few root causes: the wrong view, unsupported styling, or your code overriding the styled text.
Checklist to quickly diagnose the issue
- Confirm you’re editing a `TextView` (or compatible subclass).
Underline spans apply to text rendering. If you’re targeting a container layout or a view that doesn’t render text with spans, it won’t show.
- Verify the text is actually being set with spans/HTML.
Common failure: you apply `SpannableString`, but later code calls `textView.text = plainText`, replacing your spans.
- Check whether HTML/spans are enabled in your chosen path.
- HTML tags like `` may not be parsed unless you use the appropriate parsing method.
- Some libraries sanitize HTML and strip underline tags.
- Inspect substring matching when using `SpannableString`.
If `indexOf(...)` returns `-1`, you’ll end up with no underline span. This can happen when the localized text differs from the expected substring.
- Look for transformations that remove styling.
Auto-all-caps, custom transformation methods, or text replacement logic can sometimes interfere with how spans map to displayed characters.
Actionable troubleshooting tip: Add a quick debug log for the underline range (start/end indices) and ensure the span range matches the visible text exactly.
Conclusion
Underlining text on Android is straightforward when you choose the right method for the context. For developers who need dependable, partial underlines in a `TextView`, `SpannableString` with `UnderlineSpan` is the most reliable and flexible approach. For static UI, XML-based formatting may work in certain supported scenarios, while common apps often offer an Underline control that’s convenient for non-developers. If your underline doesn’t show up, follow the troubleshooting checklist—especially verifying view type, styling support, and whether later code overwrites the styled text—then test with localized strings to ensure consistent rendering.
Frequently Asked Questions
How do I underline text on Android in an app like Notes or Messages?
Many built-in Android apps don’t offer a dedicated “underline” formatting option, so you may only be able to bold or italicize text. If the app supports rich text, look for a formatting toolbar (often with “B/I/U” icons) or an “Edit” menu that includes underline. When there’s no underline support, you can try copying the text from an app that supports underlining or use a third-party editor that lets you apply underline formatting.
What’s the easiest way to underline text on Android using a keyboard or formatting shortcuts?
There usually isn’t a universal underline shortcut on Android keyboards because text styling depends on the specific app. Some apps support Markdown-style formatting (like wrapping text with underscores) but only if the app has Markdown enabled. Check the app’s formatting help—if it supports Markdown or rich text, you can often underline by using its specific syntax for Android.
Why can’t I underline text on Android even though I see bold and italic options?
Underline formatting support is controlled by each app’s text editor, not by Android itself. If the app only implements bold and italic, underline will be unavailable even if you select or highlight the text. In those cases, consider switching to an editor that supports underline, or use a workaround like HTML/Markdown support (if the app allows it) to achieve underlined text.
Which Android apps let you underline text reliably?
Text editors and note-taking apps with rich text support are your best bet for reliably underlining text on Android. Look for apps that explicitly mention “rich text,” “formatting,” or “underline” in their toolbar options or help pages. If you’re creating underlined content for sharing, a dedicated text formatting app can be more consistent than standard system apps.
What’s the best way to underline text in Android apps using code (TextView)?
If you’re building an Android app, you can underline a TextView by enabling the paint flag: `textView.setPaintFlags(textView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);`. This is the most direct and reliable method for underlining text on Android without relying on formatting controls. If you’re using HTML in Android, you can also render underlined text with `Html.fromHtml()` and an `` tag, as supported by your Android version.
References
- UnderlineSpan | API reference | Android Developers
https://developer.android.com/reference/android/text/style/UnderlineSpan.html - Paint | API reference | Android Developers
https://developer.android.com/reference/android/graphics/Paint.html#UNDERLINE_TEXT_FLAG - Spans | Views | Android Developers
https://developer.android.com/guide/topics/text/spans - SpannableString | API reference | Android Developers
https://developer.android.com/reference/android/text/SpannableString.html - Spannable | API reference | Android Developers
https://developer.android.com/reference/android/text/Spannable.html - Html | API reference | Android Developers
https://developer.android.com/reference/android/text/Html.html - HtmlCompat | API reference | Android Developers
https://developer.android.com/reference/androidx/core/text/HtmlCompat.html - TextView | API reference | Android Developers
https://developer.android.com/reference/android/widget/TextView.html - Google Scholar Google Scholar
https://scholar.google.com/scholar?q=Android+underline+text+UnderlineSpan - Google Scholar Google Scholar
https://scholar.google.com/scholar?q=Android+setPaintFlags+UNDERLINE_TEXT_FLAG+TextView