我试图将图片从http://loremflickr.com/加载到网页视图中,但它似乎无法在Android 4.3上运行。任何人都可以向我解释为什么以及如何解决这个问题? 它适用于Android 4.4和Android 5,但不适用于4.3
这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadUrlInWebView("http://loremflickr.com/320/240/dog");
}
private void loadUrlInWebView(String _URL) {
WebView mWebView = (WebView) findViewById(R.id.webviewer);
mWebView.setBackgroundColor(Color.TRANSPARENT);
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.loadUrl(_URL);
}
private class MyWebViewClient extends WebViewClient {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e("TAG", "error code " + errorCode);
}
}
logcat的
///logcat
09-30 14:32:33.387 4309-4309/com.myapplication D/dalvikvm﹕ Late-enabling CheckJNI
09-30 14:32:35.395 4309-4309/com.myapplication D/libEGL﹕ loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
09-30 14:32:35.582 4309-4309/com.myapplication D/libEGL﹕ loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
09-30 14:32:35.621 4309-4309/com.myapplication D/libEGL﹕ loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
09-30 14:32:36.035 4309-4309/com.myapplication D/OpenGLRenderer﹕ Enabling debug mode 0
09-30 14:32:36.199 4309-4309/com.myapplication D/TAG﹕ onLoadResource http://loremflickr.com/320/240/dog
09-30 14:32:37.246 4309-4309/com.myapplication D/TilesManager﹕ Starting TG #0, 0x59fe9ae8
09-30 14:32:37.246 4309-4309/com.myapplication D/TilesManager﹕ new EGLContext from framework: 59ebc0c0
09-30 14:32:37.246 4309-4309/com.myapplication D/GLWebViewState﹕ Reinit shader
09-30 14:32:37.262 4309-4309/com.myapplication D/GLWebViewState﹕ Reinit transferQueue
09-30 14:32:37.317 4309-4398/com.myapplication W/PicturePileLayerContent﹕ Warning: painting PicturePile without content!
09-30 14:32:37.324 4309-4398/com.myapplication W/PicturePileLayerContent﹕ Warning: painting PicturePile without content!
09-30 14:32:37.324 4309-4398/com.myapplication W/PicturePileLayerContent﹕ Warning: painting PicturePile without content!
答案 0 :(得分:1)
不要使用
loadUrlInWebView("http://loremflickr.com/320/240/dog");
使用
loadUrl("http://loremflickr.com/320/240/dog");
最后
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadUrlInWebView();
}
private void loadUrlInWebView() {
WebView mWebView = (WebView) findViewById(R.id.webviewer);
mWebView.loadUrl("http://loremflickr.com/320/240/dog");
mWebView.setBackgroundColor(Color.TRANSPARENT);
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.getSettings().setUseWideViewPort (true);
}
private class MyWebViewClient extends WebViewClient {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.e("TAG", "error code " + errorCode);
}
}
详情:
https://developer.android.com/reference/android/webkit/WebView.html
答案 1 :(得分:0)
你可以试试这个:
WebView mWebView = (WebView) findViewById(R.id.webviewer);
mWebView.loadUrl("http://loremflickr.com/320/240/dog");
只需加载图像,它肯定会有用。