作者:如果不曾相识_不曾相知_不曾相恋 | 来源:互联网 | 2023-05-18 22:03
在网上看我可以再strings.xml中创建string实现超链接。流程如下:
strings.xml
CBT
Hello world!
Touch ""HERE
布局文件:
android:id="@+id/test"
android:layout_
android:layout_
android:clickable="true"
android:text="@string/HERE"
android:textColor="@android:color/white"
android:layout_gravity="center"
/>
"Here"字段确实能显示为超链接样式,表现为字体蓝色、有下划线,但是就是不能跳转。
最后在OnCreate()方法中加上一段:
TextView textView = (TextView) findViewById(R.id.test);
textView.setMovementMethod(LinkMovementMethod.getInstance());
也可以这样:
TextView textView = (TextView) findViewById(R.id.test);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String html = " Touch "+""+"HERE";
textView.setText(Html.fromHtml(html));
但不够灵活!