为什么链接在文本视图中不起作用? [英] Why link does not work in the text view?
本文介绍了为什么链接在文本视图中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 TextView 中有链接:
I have the link in my TextView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
...
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:linksClickable="true"
android:text="@string/app_description" />
</RelativeLayout>
链接是资源的一部分:
<?xml version="1.0" encoding="utf-8"?>
<resources>
...
<string name="app_description">Some text with the <a href="http://www.example.com">link</a>.</string>
</resources>
不知何故链接不起作用.可能是什么原因?它像链接一样显示.但是单击不会打开浏览器.
Somehow the link doesn't work. What could be a reason? It is displayed like a link. But click doesn't open the browser.
课程代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
推荐答案
你可以这样使用http链接:
you can use http link this way:
mLink = (TextView) findViewById(R.id.link);
if (mLink != null) {
mLink.setMovementMethod(LinkMovementMethod.getInstance());
}
在 XML 中:
android:autoLink="all"
这篇关于为什么链接在文本视图中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文