本文介绍了基于String.xml在TextView中设置超链接的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我string.xml串线
<字符串名称=companyLink>&放大器; LT; A HREF =安培; QUOT; HTTP://www.abc.com& QUOT;&放大器; GT; ABC科技及; LT; / A> < /串>
和这是我尝试使用HTML
TextView的companylink =(的TextView)findViewById(R.id.textViewCompanyLink);
companylink.setText(Html.fromHtml(的getString(R.string.companyLink)));
companylink.setMovementMethod(LinkMovementMethod.getInstance());
不过Android的只显示出HTML没有的超级链接
在屏幕上
< A HREF = HTTP://abc.com> ABC串< / A>
解决方案
的报价也应该逃脱,否则Java将在的getString删除()。之前和放大器添加反斜杠; QUOT;
<字符串名称=companyLink>&放大器; LT; A HREF = \\&放大器; QUOT; HTTP://www.abc.com \\&放大器; QUOT;&安培; GT; ABC科技及; LT; / A> < /串>
还是这个解决方案,为我工作:
my string.xml string line
<string name="companyLink"><a href="http://www.abc.com">abc Technology </a> </string>
and this is how i try to use the html
TextView companylink = (TextView) findViewById(R.id.textViewCompanyLink);
companylink.setText(Html.fromHtml(getString(R.string.companyLink)));
companylink.setMovementMethod(LinkMovementMethod.getInstance());
however android only display out the html without the hyperlink on the screen
<a href=http://abc.com>abc string </a>
解决方案
The quotes should also be escaped otherwise Java will remove them during getString(). Add backslashes before "
<string name="companyLink"><a href=\"http://www.abc.com\">abc Technology </a> </string>
Or this solution that worked for me:
http://stackoverflow.com/a/9949264/1011746
这篇关于基于String.xml在TextView中设置超链接的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!