我有正在加载 URL 的 WebView 。
当我加载 http://www.google.co.in/ 时它工作正常
但是,当我加载时它没有显示任何内容 http://edition.cnn.com/它用这个 url 打开浏览器。
为什么会发生这种情况以及如何避免这种情况。
提前致谢...!
最佳答案
edition.cnn.com 将您重定向到移动网站版本
http://developer.android.com/resources/tutorials/views/hello-webview.html
You now have a simplest web page viewer. It's not quite a browser yet because as soon as you click a link, the default Android Browser handles the Intent to view a web page, because this Activity isn't technically enabled to do so. Instead of adding an intent filter to view web pages, you can override the WebViewClient class and enable this Activity to handle its own URL requests.
示例:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
WebView w = (WebView) findViewById(R.id.webView);
w.getSettings().setJavaScriptEnabled(true);
w.setWebViewClient(new HelloWebViewClient());
w.loadUrl("http://edition.cnn.com/");
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
关于android - 为什么 WebView 不加载特定的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8065457/