I am creating simple Webview
application with some links on textview
and open those links in webview
instead of default browser. My
The most important part of @Emanuel Moecklin 's answer is to subclass URLSpan
and create your own URLSpan
which has onClick
overrided.
Inspired by his answer, instead of following fully his steps, I sticked to using Linkify
. However, for some other reasons, I created my own Linkify
class, with almost the same code as original Linkify
.
And then, inside applyLink()
in Linkify, I replaced
URLSpan span = new URLSpan(url);
with
InAppURLSpan span = new InAppURLSpan(url);
Where the code for InAppURLSpan
is:
public static class InAppURLSpan extends URLSpan {
public InAppURLSpan(String url) {
super(url);
}
@Override
public void onClick(View widget) {
String url = getURL();
Log.i("TNC_URL", url);
Intent intent = new Intent(widget.getContext(), SingleWebViewActivity.class);
intent.putExtra(Constants.INTENT_URL, url);
widget.getContext().startActivity(intent);
}
}
And it worked like a charm~