android - 如何从 Android strings.xml 中的 anchor 链接中删除格式

标签 android css textview android-xml

我有一个包含如下 HTML 链接的字符串:

<string name="text_with_link"><a href="openDocument://document1.html"><b>This</b></a> and <a href="openDocument://document2.html"><b>this</b></a> are links</string>

如您所见,我希望链接为粗体。不过,这是我希望链接具有的唯一格式。然而,结果看起来像这样:

enter image description here

如何去除链接的下划线和颜色?

我尝试以下列形式添加 style="text-decoration:none;"

<a href="openDocument://document2.html" style="text-decoration:none;">

<a href="openDocument://document2.html" style="text-decoration:none !important;">

<style>a {text-decoration:none;}</style><a href="openDocument://document1.html"><b>This</b></a>

.. 但运气不好。 CSS 似乎不适用于 Android 字符串。

最佳答案

您必须使用 Html.fromHtml 进行格式化才能像这样工作:

tv = (TextView) findViewById (R.id.textviewid);       
tv.setText(Html.fromHtml(getResources.getString(R.string.text_with_link)));

还要更改链接颜色,您必须在 TextView XML 中使用 android:textColorLink 属性来更改链接颜色。

CSS 不适用于 android 字符串。

关于android - 如何从 Android strings.xml 中的 anchor 链接中删除格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32967410/

相关文章:

android - JSONObject.toString() 将内部 JSONArray 转换为 Android 中的字符串

java - 找不到媒体类型 = application/json 的 MessageBodyReader - android

html - 如何排列列表中的每个单词,以便条目水平地从同一点开始?

javascript - HTML 模板呈现 - 奇怪的行为

android - 具有 9 补丁图像背景的项目中的 Textview 位置不正确

android - 如何在 android 的 TextView 中显示两种字体的句子组合?

android - app暂停一段时间后FragmentActivity丢失

android - 动态获取可绘制对象的原色以设置工具栏颜色

jquery - 使用 html 和 css 创建动态储 jar 液位/仪表

android - 使用 Android Espresso 检查 TextView 的文本是否完全显示