This is due to the fact that it TextViewcreates URLSpanwhich ClickableSpanfor each link text template. When it MovementMethodfinds the url, it calls the method onClick URLSpan. This event triggers the intent ACTION_VIEW, so you see the default browser instead.
, URLSpan, onClick CustomTabs.
URLSpan, onClick:
public class CustomTabsURLSpan extends URLSpan {
public CustomTabsURLSpan(String url) {
super(url);
}
public CustomTabsURLSpan(Parcel src) {
super(src);
}
@Override
public void onClick(View widget) {
String url = getUrl();
}
}
, :
public class LinkTransformationMethod implements TransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
Linkify.addLinks(textView, Linkify.WEB_URLS);
String stringText = textView.getText().toString();
Spannable text = (Spannable) textView.getText();
URLSpan[] spans = text.getSpans(0, textView.length(), URLSpan.class);
for (int i = spans.length - 1; i >= 0; i--) {
URLSpan oldSpan = spans[i];
text.removeSpan(oldSpan);
String url = oldSpan.getURL();
int startIndex = stringText.indexOf(url);
int lastIndex = startIndex + url.length();
text.setSpan(new CustomTabsURLSpan(url), startIndex, lastIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return text;
}
return source;
}
@Override
public void onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction, Rect previouslyFocusedRect) {
}
}
: https://medium.com/@nullthemall/make-textview-open-links-in-customtabs-12fdcf4bb684#.ig1chpbbe