Mukul Jain
Mukul Jain

Reputation: 1927

TextView Html formatting

I have a textview which should render its content with HTML formatting. From code, this can be achieved like this,

textView.setText(Html.fromHtml(someText));

Is there a way to do this through the XML?

I ask because i do not want to set the text through the code, In my case, the text comes from a DB call and displayed through an adapter.

Upvotes: 3

Views: 5181

Answers (1)

Heiko Rupp
Heiko Rupp

Reputation: 30934

Yes there are a bunch of (simple) tags that are understood by TextView -- if the text is set in XML from a string resource.

So basically

<TextView text="@string/foo" .. />

It is also possible to give templates like "Hello <b>%s</b>", but here you still need to run some code to fill in the value for %s

Have a look at http://developer.android.com/guide/topics/resources/string-resource.html for formatting hints and short examples.

Upvotes: 1

Related Questions