我想为 textview 文本创建一个链接,例如 Google .反正有没有这样的链接。 (即)单击 Google 一词时,应打开相应的链接。欢迎任何想法。
最佳答案
试试这个,让我知道会发生什么..
使用java代码:
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));
从 API 级别 >= 24 开始,Html.fromHtml(String source)
已弃用,而是使用 fromHtml(String, int)
,
textView.setText(Html.fromHtml(text, Html.FROM_HTML_MODE_COMPACT));
或者在布局 xml 文件中,在 TextView 小部件属性中
android:autoLink="web"
android:linksClickable="true"
关于android - 在android中制作超链接textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9290651/