Issue
When I click a link inside my WebView, Android open browser instead of changing URL in WebView.
Here's my fragment where WebView is (R.layout.webview contain WebView only):
package com.example.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
public class EuDetailsFragment extends Fragment {
private WebView viewer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
viewer = (WebView) inflater.inflate(R.layout.webview, container, false);
return viewer;
}
public void updateUrl(String newUrl) {
Log.d("EuDetailsFragment", "Updating url...");
WebView detailsView = (WebView) getView().findViewById(R.id.detailsView);
detailsView.loadUrl(newUrl);
}
}
Solution
The default behavior is that when you click a link it will ask the ActivityManager to find an appropriate app to handle the link. You may override this behavior(which will force the current WebView to load the new url in itself instead) like this:
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
return false;
}
});
Answered By - FoamyGuy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.