问题
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