Android Webview Opens Page In Default Browser Instead Of My Webview
I am trying for two days to find a code to work with what I have.. I am following this tutorial: http://techvalleyprojects.blogspot.ro/2011_08_01_archive.html I have the following
Solution 1:
You need to implement setWebViewClient(....)
like so.
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
Update:
Make your Activity like so
public class MainActivity extends Activity {
WebView browser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// find the WebView by name in the main.xml of step 2
browser=(WebView)findViewById(R.id.wvwMain);
// Enable javascript
browser.getSettings().setJavaScriptEnabled(true);
// Set WebView client
browser.setWebChromeClient(new WebChromeClient());
browser.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
// Load the webpage
browser.loadUrl("http://news.google.com/");
}
}
Solution 2:
Add this setContentView(browser);
instead of setContentView(R.layout.activity_main);
, but add it at the end of the method.
Edit:
Also, add this:
browser.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
});
Post a Comment for "Android Webview Opens Page In Default Browser Instead Of My Webview"