Auto link property different text with the actual linking (setAutoLinkMask)

孤者浪人 提交于 2019-12-12 13:19:16

问题


For example

TextView tv =(TextView)this.findViewById(R.id.tv);
tv.setAutoLinkMask(Linkify.ALL);
tv.setText("visit website, http://www.google.com");

pressing on http://www.google.com will take me to http://www.google.com. The thing I want to do is like this

TextView tv =(TextView)this.findViewById(R.id.tv);
tv.setAutoLinkMask(Linkify.ALL);
tv.setText("visit this website");

and pressing on "this" I want to take me to http://www.google.com.

How can I do this ? (is it possible at all ?)


回答1:


From API Demo,

TextView t3 = (TextView) findViewById(R.id.text3);
t3.setText(Html.fromHtml(
                    "<b>text3:</b>  Text with a " +
                    "<a href=\"http://www.google.com\">link</a> " +
                    "created in the Java source code using HTML."));
t3.setMovementMethod(LinkMovementMethod.getInstance());



回答2:


You can just use the attribute android:text="@string/url" as the TextView attribute. Make sure to put a valid URL as the value of the TextView.



来源:https://stackoverflow.com/questions/7951752/auto-link-property-different-text-with-the-actual-linking-setautolinkmask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!