我想在 textview 上显示 hyperLinke 而不是在 url 上,例如:嗨,“url”怎么样。(这里的 url 将打开 www.google.com)。所有这些都将出现在警报对话框中..
我遵循了以下方法,但没有得到正确的解决方案..
String.xml---
谷歌
String str = getResources().getString(R.string.link);
final TextView txtvw = new TextView(this);
txtvw.setText(Html.fromHtml(str));
txtvw.setClickable(true);
txtvw.setAutoLinkMask(RESULT_OK);
txtvw.setMovementMethod(LinkMovementMethod.getInstance());
Linkify.addLinks(txtvw, Linkify.WEB_URLS);
AlertDialog.Builder alt_bld = new AlertDialog.Builder(context);
alt_bld.setTitle(title);
alt_bld.setCancelable(false);
alt_bld.create();
alt_bld.setView(txtvw).show();
最佳答案
使用 CDATA 标签:
<string name="link"><![CDATA[ <a href="http://www.google.co.in">Google</a> ]]></string>
更新:
String str = getResources().getString(R.string.link);
final TextView txtvw = new TextView(this);
txtvw.setText(Html.fromHtml(str));
txtvw.setMovementMethod(LinkMovementMethod.getInstance());
new AlertDialog.Builder(context)
.setTitle(title)
.setCancelable(false)
.setView(txtvw)
.show();
关于android - 没有 url 的 TextView 上的超链接未显示且不可单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14213184/