在网上看我可以再strings.xml中创建string实现超链接。流程如下:
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CBT</string>
<string name="hello_world">Hello world!</string>
<string name="HERE"><font size="20"> Touch </font>""<a href="http://zhidao.baidu.com">HERE</a></string>
</resources>
布局文件:
<TextView
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:text="@string/HERE"
android:textColor="@android:color/white"
android:layout_gravity="center"
/>
"Here"字段确实能显示为超链接样式,表现为字体蓝色、有下划线,但是就是不能跳转。
最后在OnCreate()方法中加上一段:
<span style="white-space:pre"> </span>TextView textView = (TextView) findViewById(R.id.test);
<span style="white-space:pre"> </span>textView.setMovementMethod(LinkMovementMethod.getInstance());
也可以这样:
TextView textView = (TextView) findViewById(R.id.test);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String html = "<font size='20'> Touch </font>"+""+"<a href='http://zhidao.baidu.com'>HERE</a>";
textView.setText(Html.fromHtml(html));
但不够灵活!