How to Color part of TextView in Android

Use HTML-escapes + Html.fromHtml()

The trick here is to add HTML Tags for styling in the String and then set that String to TextView.

Code:

Keep the string in string (resource)folder like this:

Read the string from string (resource)folder like this

String text = this.getResources().getString(R.string.textFromRes);
htmlText.setText(Html.fromHtml(text));

Output:

Note: The string shown in the above output looks like this

Putting up content takes a lot of time and effort 😓.
👏 clap 👏 If you think you learned something from this article.You can find me on Stackoverflow,Github,and,on Linkedin.
Give feedback and feel free to correct mistakes.

--

--

--

Android Developer | Arizona State University | NASA Psyche Research Aide

Love podcasts or audiobooks? Learn on the go with our new app.

Paytm Checksum Generate in Android(NoSuchProviderException: No such provider: SunJCE)

Adapt your app for the latest privacy best practices

Jetpack Compose

TextInputLayout Form Validation Using Data Binding in Android

Hands holding phone

How to Add Floating Bubbles or Chat Heads to Window

Android TaskStackBuilder

Android Foreground Service Restrictions

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rohit Singh

Rohit Singh

Android Developer | Arizona State University | NASA Psyche Research Aide

More from Medium

Expert: Integration of HMS Core Kits in Expense Android App

Android Telephony Overview

How to Deal with Quantity Texts in Multi-Language App in Android

How to register keyboard shortcuts in Android’s menu to inform users