HTML中的字符串资源? [英] HTML in string resource?
问题描述
我知道我可以把转义的HTML标签字符串资源。然而,查看源$ C $ C为联系人应用程序,我可以看到,他们不必EN code中的HTML的一种方式。从联系人应用程序<报价href="http://android.git.kernel.org/?p=platform/packages/apps/Contacts.git;a=blob;f=res/values/strings.xml;h=e37c1182741baf957fa47c3b2fc345be86b659c1;hb=HEAD">strings.xml:
I know I can put escaped HTML tags in string resources. However, looking at the source code for the Contacts application I can see that they have a way of not having to encode the HTML. Quote from the Contacts application strings.xml:
<string name="contactsSyncPlug"><font fgcolor="#ffffffff">Sync your Google contacts!</font>
\nAfter syncing to your phone, your contacts will be available to you wherever you go.</string>
不幸的是,当我尝试类似的东西(如您好,&LT; B&GT;世界&LT; / B&GT;!
),的getString()
返回无标签的字符串(我可以看到,在的logcat
)。这是为什么?我怎样才能得到原始的字符串,用标签和一切?联系人应用程序是怎么样的呢?
Unfortunately, when I try something similar (like Hello, <b>World</b>!
), getString()
returns the string without the tags (I can see that in logcat
). Why is that? How can I get the original string, with tags and everything? How is the Contacts application doing it?
推荐答案
这似乎的getString()
正是如此 - 得到一个字符串 。要使用此功能,你必须使用的getText()
(并没有更多的 Html.fromHtml()
),即:
It seems getString()
does just that -- gets a string. To use this, you have to use getText()
(and no more Html.fromHtml()
), i.e.:
mTextView.setText(getText(R.string.my_styled_text));
不过,似乎安卓文本
属性不一样的东西,以下是等价的:
However, it seems the android:text
property does just the same thing, and the following is equivalent:
<TextView android:text="@string/my_styled_text" />
而在的strings.xml
:
<string name="my_styled_text">Hello, <b>World</b>!</string>
这篇关于HTML中的字符串资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!