Issue
I am trying to load a website in the webview, but when I open the app, it doesn't load anything, instead it opens the link in the default browser.. How can I make it load in my webview? The code has no errors in eclipse but it doesn't do what it should.. What am I doing wrong?
package com.example.name;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
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());
// Load the webpage
browser.loadUrl("http://www.website.com/");
}
}
Solution
Try to set custom WebViewClient
:
browser.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
});
WebChromeClient
let you handle JavaScript
functions.
WebViewClient
let you handle loading page (shouldOverrideUrlLoading()
) and complete loading page (onPageFinished()
).
Answered By - nfirex
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.