开发者

TextView Html formatting

开发者 https://www.devze.com 2023-02-10 22:02 出处:网络
I have a textview which should render its content with HTML formatting. From code, this can be achieved like this,

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开发者_Go百科 call and displayed through an adapter.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消