Reputation: 315
I have a HTML text like this:
val text = "Please click <a href=\"https://google.com\">here</a> for read the message. "
And I set to my TextView.
binding.textLabel.text = Html.fromHtml(text)
However, the link opening in browser instead of the application. I want it to open within the app. How can I do it?
Upvotes: 0
Views: 94
Reputation: 5173
Do it in two steps
If it still persists use the android:autoLink=""
attribute.
If you want further links to open in the webview itself use
ebView.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});
Upvotes: 1