很抱歉问这个新手问题,因为我是 android 开发的新手。 main.java 中应该输入什么代码?
<resources>
<string name="strname">Clickable Text<a href="http://domain.com">Visit Website</a></string>
</resources>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:autoLink="web"
android:text="@string/strname"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
最佳答案
你可以使用Linkfy :
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText("http://www.google.com");
Linkify.addLinks(textView, Linkify.WEB_URLS);
来自文档
Linkify take a piece of text and a regular expression and turns all of the regex matches in the text into clickable links
关于android - 如何使 Textview 可点击,以便它在网络浏览器中打开 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28381809/