How to make XML strings bold, underlined etc?

删除回忆录丶 提交于 2019-12-04 23:58:37

Try wrapping your marked up text in CDATA tags. For example:

<string name="ss"><![CDATA[<b>Bold.</b> <u>Underlined.</u> <i>Italic.</i> <big>Big.</big> <small>Small</small>]]></string>

And then use Html.fromHtml wherever you're wanting to display it:

Html.fromHtml(getString(R.string.ss))

This problem has been driving me crazy for ages. It's something sooo simple that you just want it to work!!!

Anyway I've found an answer here at http://www.coderzheaven.com/2011/06/19/styling-text-in-android-through-xml/

The key is to load the resource as a CharSequence using getResources().getText(R.string.xxxx) this will retain all the style information and allow you to use inline styling tags. My mistake was using getString() because when loading your resource getString() will cause the string to lose all its style information.

exemple:

<string name="ss"><font size="15"><b>Parrainage</b></font><u>subscribe</u></string>

b = bold et u = underline .....etc

This is working for me.

<string name="welcome_messages">Hello, %1$s! You have &lt;b>%2$d new messages&lt;/b>.</string>

txt.setText(Html.fromHtml(getString(R.string.welcome_messages)));

more details check Official site: https://developer.android.com/guide/topics/resources/string-resource.html#StylingWithSpannables

in dimens file write:

<dimen name="size_edittext">180dp</dimen>

and in your xml layout or activity call it:

android:@dimen/ size_edittext
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!