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(newWebViewClient() {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
returntrue;
}
});
Update:
Make your Activity like so
publicclassMainActivityextendsActivity {
WebView browser;
@OverrideprotectedvoidonCreate(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(newWebChromeClient());
browser.setWebViewClient(newWebViewClient() {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
returntrue;
}
});
// Load the webpage
browser.loadUrl("http://news.google.com/");
}
}
Post a Comment for "Android Webview Opens Page In Default Browser Instead Of My Webview"