我有一个包含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>
正如您所注意到的,我希望链接是粗体的。不过,这是我想要链接的唯一格式。但是,结果如下所示:
如何从链接中删除下划线和颜色?
我已尝试在以下表单中添加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字符串。
答案 0 :(得分:0)
您必须使用Html.fromHtml
进行格式设置才能正常工作:
tv = (TextView) findViewById (R.id.textviewid);
tv.setText(Html.fromHtml(getResources.getString(R.string.text_with_link)));
还要更改链接颜色,您必须在文本视图XML中使用android:textColorLink
属性来更改链接颜色。
CSS在android字符串中不起作用。